-
-
Save niektemme/773da6528bab9b0c1e90 to your computer and use it in GitHub Desktop.
Smart Thermostat Raspberry PI - part database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import apsw #alternative python sqlite wrapper | |
# sqllite settings | |
vuri = ':memory:' | |
dbc = apsw.Connection(vuri) | |
def dbstart(): | |
""" | |
Initial tables | |
Creates required in memmory tables and indexes. | |
Runs once when script is started. | |
""" | |
try: | |
db1 = dbc.cursor() | |
db1.execute("DROP TABLE IF EXISTS sensvals") | |
db1.execute("CREATE TABLE sensvals(vkey TEXT, vepoch INT, vsub INT, vsource TEXT, vport TEXT, vprekey TEXT, vvalue INT)") | |
db1.execute("CREATE UNIQUE INDEX isens1 on sensvals(vkey)") | |
db1.execute("CREATE INDEX isens2 on sensvals(vepoch)") | |
db1.execute("CREATE INDEX isens3 on sensvals(vsource)") | |
db1.execute("CREATE INDEX isens4 on sensvals(vport)") | |
db1.execute("CREATE INDEX isens5 on sensvals(vprekey)") | |
except Exception: | |
logging.exception("dbstart") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment