aboutsummaryrefslogtreecommitdiff
path: root/src/db/task_tags.py
diff options
context:
space:
mode:
authorJoris2020-05-31 13:59:35 +0200
committerJoris2020-05-31 13:59:35 +0200
commit0f1610333324d58acafee8c0fa9d9c9bc293b219 (patch)
tree302c37dd3751e9fe2e50ab656d56253bfd2d55fc /src/db/task_tags.py
parent8a6e10d401eea8db0947f8c4b309b8a6256f9748 (diff)
downloadtodo-0f1610333324d58acafee8c0fa9d9c9bc293b219.tar.gz
todo-0f1610333324d58acafee8c0fa9d9c9bc293b219.tar.bz2
todo-0f1610333324d58acafee8c0fa9d9c9bc293b219.zip
Use defined tags for tasks
Diffstat (limited to 'src/db/task_tags.py')
-rw-r--r--src/db/task_tags.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/db/task_tags.py b/src/db/task_tags.py
new file mode 100644
index 0000000..34366e0
--- /dev/null
+++ b/src/db/task_tags.py
@@ -0,0 +1,30 @@
+from sqlite3 import Cursor
+import time
+from typing import List
+
+from model.task_tag import TaskTag
+
+def get(cursor: Cursor) -> List[TaskTag]:
+ cursor.execute("SELECT task_id, tag_id FROM task_tags")
+ return [TaskTag(r[0], r[1]) for r in cursor.fetchall()]
+
+def insert_many(cursor: Cursor, task_id: int, tag_ids: List[int]) -> List[TaskTag] :
+ now = int(time.time())
+
+ task_tags = [TaskTag(task_id = task_id, tag_id = tag) for tag in tag_ids]
+
+ cursor.executemany(
+ " INSERT INTO task_tags("
+ " task_id,"
+ " tag_id,"
+ " created_at"
+ " ) VALUES (?, ?, ?)",
+ [(t.task_id, t.tag_id, now) for t in task_tags])
+
+ return task_tags
+
+def delete(cursor: Cursor, task_ids: List[int]):
+ if len(task_ids) >= 1:
+ cursor.execute(
+ 'DELETE FROM task_tags WHERE task_id IN (%s)' % ','.join('?'*len(task_ids)),
+ task_ids)