44 lines
933 B
Python
44 lines
933 B
Python
|
|
import sqlite3
|
|
import os
|
|
|
|
class DataStore:
|
|
def __init__(self, dbfile):
|
|
if not os.path.exists(dbfile):
|
|
self.createdb(dbfile)
|
|
self.conn = sqlite3.connect(dbfile)
|
|
|
|
def __del__(self):
|
|
self.conn.close()
|
|
|
|
def createdb(self, dbfile):
|
|
conn = sqlite3.connect(dbfile)
|
|
c = conn.cursor()
|
|
c.execute('''
|
|
CREATE TABLE tasks (
|
|
id INTEGER PRIMARY KEY,
|
|
name TEXT,
|
|
longname TEXT,
|
|
parentid INTEGER,
|
|
FOREIGN KEY (parentid) REFERENCES tasks(id)
|
|
)''')
|
|
c.execute('''
|
|
CREATE TABLE entries (
|
|
date TEXT,
|
|
taskid INTEGER,
|
|
seconds INTEGER,
|
|
PRIMARY KEY (date, taskid),
|
|
FOREIGN KEY (taskid) REFERENCES tasks(id)
|
|
)''')
|
|
c.execute('''
|
|
CREATE TABLE history (
|
|
id INTEGER PRIMARY KEY,
|
|
taskid INTEGER,
|
|
datetime TEXT,
|
|
FOREIGN KEY (taskid) REFERENCES tasks(id)
|
|
)''')
|
|
conn.commit()
|
|
c.close()
|
|
conn.close()
|
|
|