From 6ed4e669ef7cb857c7b0ac774c41e8f9c7758217 Mon Sep 17 00:00:00 2001 From: Joris Date: Fri, 8 May 2020 19:35:08 +0200 Subject: Add duration to tasks --- src/db/init.py | 1 + src/db/tasks.py | 54 +++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 42 insertions(+), 13 deletions(-) (limited to 'src/db') 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) -- cgit v1.2.3