Refactor tag crud operations

This commit is contained in:
Peter Stockings
2023-12-09 17:19:49 +11:00
parent 4da03ad2ad
commit fd6ca240ee
4 changed files with 20 additions and 23 deletions

20
db.py
View File

@@ -268,10 +268,10 @@ class DataBase():
def get_tags_for_person(self, person_id):
return self.execute("""
SELECT
T.tag_id AS "TagId",
T.person_id AS "PersonId",
T.name AS "TagName",
T.filter AS "TagFilter"
T.tag_id as "tag_id",
T.person_id as "person_id",
T.name AS "tag_name",
T.filter AS "tag_filter"
FROM
Tag T
WHERE
@@ -298,10 +298,10 @@ class DataBase():
def get_tags_for_dashboard(self):
return self.execute("""
SELECT
T.tag_id AS "TagId",
T.person_id AS "PersonId",
T.name AS "TagName",
T.filter AS "TagFilter"
T.tag_id AS "tag_id",
T.person_id AS "person_id",
T.name AS "tag_name",
T.filter AS "tag_filter"
FROM
Tag T
WHERE
@@ -311,12 +311,12 @@ class DataBase():
def add_or_update_tag_for_dashboard(self, tag_name, tag_filter):
# check if a tag exists for dashboard with the same tag_name
tag = self.execute('SELECT tag_id AS "TagId" FROM Tag WHERE person_id IS NULL AND name=%s LIMIT 1', [
tag = self.execute('SELECT tag_id AS "tag_id" FROM Tag WHERE person_id IS NULL AND name=%s LIMIT 1', [
tag_name], one=True)
if tag:
# update the tag
self.execute('UPDATE Tag SET filter=%s WHERE tag_id=%s', [
tag_filter, tag['TagId']], commit=True)
tag_filter, tag['tag_id']], commit=True)
else:
self.execute('INSERT INTO Tag (name, filter) VALUES (%s, %s)', [
tag_name, tag_filter], commit=True)