initial sqlite integration

This commit is contained in:
Pratyush Desai 2021-12-04 17:14:49 +05:30
parent 70a6114456
commit 8c1679382f
Signed by: pratyush
GPG Key ID: DBA5BB7505946FAD
2 changed files with 36 additions and 1 deletions

1
.gitignore vendored
View File

@ -0,0 +1 @@
.vscode

View File

@ -38,12 +38,46 @@ except ImportError:
# without the i18n module # without the i18n module
_ = lambda x: x _ = lambda x: x
import os
import sqlite3
class SqliteDoselogsDB(object):
def __init__(self, filename):
self.db = {}
self.filename = filename
def close(self):
self.db.close()
def _getDb(self):
filename = os.path.basename(self.__class__.__name__)
if filename in self.db:
return self.db[filename]
if os.path.exists(filename):
db = sqlite3.connect(filename, check_same_thread=False)
self.db[filename] = db
return db
db = sqlite3.connect(filename, check_same_thread=False)
self.db[filename] = db
cursor = db.cursor()
cursor.execute("""CREATE TABLE doselogs (
id INTEGER PRIMARY KEY,
username TEXT,
nick TEXT,
timezone TEXT,
amount TEXT,
drug TEXT,
roa TEXT,
timestamp TEXT
)
""")
class DoseLogs(callbacks.Plugin): class DoseLogs(callbacks.Plugin):
"""Log and annotate your doses""" """Log and annotate your doses"""
threaded = True threaded = True
Class = DoseLogs Class = DoseLogs