Stub out db upsert code for stations table in test_db.py.
See table definition at #30 (comment).
This commit is contained in:
parent
c25a10ae77
commit
1c057a5555
29
test_db.py
Normal file
29
test_db.py
Normal file
|
@ -0,0 +1,29 @@
|
|||
|
||||
# Learn how to update database
|
||||
|
||||
import sqlite3
|
||||
|
||||
def get_db_connection():
|
||||
conn = sqlite3.connect('database.db')
|
||||
conn.row_factory = sqlite3.Row
|
||||
return conn
|
||||
|
||||
conn = get_db_connection()
|
||||
|
||||
# example https://stackoverflow.com/a/50718957/2152245
|
||||
query1 = "INSERT INTO players (user_name, age) \
|
||||
VALUES('steven', 32) \
|
||||
ON CONFLICT(user_name) \
|
||||
DO UPDATE SET age=excluded.age;"
|
||||
|
||||
query2 = "INSERT INTO stations (id, 'from', frames_id, last_heard_unix, count) \
|
||||
VALUES(1, 'KC9TZN-9', 4068, 1687623864, 1) \
|
||||
ON CONFLICT(id) \
|
||||
DO UPDATE SET count = count + 1;"
|
||||
|
||||
query3 = "INSERT INTO stations ('from', frames_id, last_heard_unix, count) \
|
||||
VALUES('KC9TZN-9', 4068, 1687623864, 1)"
|
||||
|
||||
conn.execute(query2)
|
||||
conn.commit()
|
||||
conn.close()
|
Loading…
Reference in New Issue
Block a user