dwtt/DataStore.py

42 lines
908 B
Python

import sqlite3
import os
class DataStore:
def __init__(self, timedbfile):
if not os.path.exists(timedbfile):
self.createdb(timedbfile)
self.conn = sqlite3.connect(timedbfile)
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 INTEGER PRIMARY KEY,
taskid INTEGER,
hours REAL,
FOREIGN KEY (taskid) REFERENCES tasks(id)
)''')
c.execute('''
CREATE TABLE history (
id INTEGER PRIMARY KEY,
taskid INTEGER,
FOREIGN KEY (taskid) REFERENCES tasks(id)
)''')
conn.commit()
c.close()
conn.close()