aboutsummaryrefslogtreecommitdiff
path: root/src/db
diff options
context:
space:
mode:
Diffstat (limited to 'src/db')
-rw-r--r--src/db/init.py1
-rw-r--r--src/db/tasks.py54
2 files changed, 42 insertions, 13 deletions
diff --git a/src/db/init.py b/src/db/init.py
index 9517714..c1835eb 100644
--- a/src/db/init.py
+++ b/src/db/init.py
@@ -12,6 +12,7 @@ def init(path):
" created_at INTEGER NOT NULL,"
" modified_at INTEGER NOT NULL,"
" name TEXT NOT NULL,"
+ " duration INTEGER,"
" tag TEXT"
" )")
database.commit()
diff --git a/src/db/tasks.py b/src/db/tasks.py
index 26a430a..d03877b 100644
--- a/src/db/tasks.py
+++ b/src/db/tasks.py
@@ -1,10 +1,18 @@
from sqlite3 import Cursor
import time
-from model.task import Task, TaskForm
+from model.task import Task, ValidTaskForm
def get(cursor: Cursor) -> Task:
- cursor.execute('SELECT id, created_at, modified_at, name, tag FROM tasks')
+ cursor.execute(
+ " SELECT"
+ " id,"
+ " created_at,"
+ " modified_at,"
+ " name,"
+ " duration,"
+ " tag"
+ " FROM tasks")
res = []
@@ -14,37 +22,57 @@ def get(cursor: Cursor) -> Task:
created_at = task[1],
modified_at = task[2],
name = task[3],
- tag = task[4]
+ duration = task[4],
+ tag = task[5]
))
return res
-def insert(cursor: Cursor, taskForm):
+def insert(cursor: Cursor, form: ValidTaskForm):
now = int(time.time())
- cursor.execute('INSERT INTO tasks(created_at, modified_at, name, tag) VALUES (?, ?, ?, ?)', (now, now, taskForm.name, taskForm.tag))
+ cursor.execute(
+ " INSERT INTO tasks("
+ " created_at,"
+ " modified_at,"
+ " name,"
+ " duration,"
+ " tag"
+ " ) VALUES (?, ?, ?, ?, ?)",
+ (now, now, form.name, form.duration, form.tag))
+
return Task(
id = cursor.lastrowid,
created_at = now,
modified_at = now,
- name = taskForm.name,
- tag = taskForm.tag
+ name = form.name,
+ duration = form.duration,
+ tag = form.tag
)
-def update(cursor: Cursor, task: Task, taskForm: TaskForm):
+def update(cursor: Cursor, task: Task, form: ValidTaskForm):
now = int(time.time())
cursor.execute(
- 'UPDATE tasks SET modified_at = ?, name = ?, tag = ? WHERE id = ?',
- (now, taskForm.name, taskForm.tag, task.id))
+ " UPDATE tasks"
+ " SET"
+ " modified_at = ?,"
+ " name = ?,"
+ " duration = ?,"
+ " tag = ?"
+ " WHERE id = ?",
+ (now, form.name, form.duration, form.tag, task.id))
return Task(
id = task.id,
created_at = task.created_at,
modified_at = now,
- name = taskForm.name,
- tag = taskForm.tag
+ name = form.name,
+ duration = form.duration,
+ tag = form.tag
)
def delete(cursor: Cursor, ids):
if len(ids) >= 1:
- cursor.execute('DELETE FROM tasks WHERE id IN (%s)' % ','.join('?'*len(ids)), ids)
+ cursor.execute(
+ 'DELETE FROM tasks WHERE id IN (%s)' % ','.join('?'*len(ids)),
+ ids)