Migrated links, lyrics and properties
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import sqlite3
|
||||
from collections.abc import Iterator
|
||||
from contextlib import contextmanager
|
||||
from typing import Iterator, Optional
|
||||
|
||||
from folkugat_web.config.db import DB_FILE
|
||||
|
||||
@@ -13,6 +13,7 @@ def get_connection(con: Connection | None = None) -> Iterator[Connection]:
|
||||
yield con
|
||||
else:
|
||||
con = sqlite3.connect(DB_FILE)
|
||||
_ = con.execute('PRAGMA foreign_keys = ON;')
|
||||
try:
|
||||
yield con
|
||||
con.commit()
|
||||
|
||||
@@ -6,12 +6,6 @@ def create_db(con: Connection | None = None):
|
||||
create_playlists_table(con)
|
||||
|
||||
|
||||
def drop_playlists_table(con: Connection):
|
||||
query = "DROP TABLE IF EXISTS playlists"
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query)
|
||||
|
||||
|
||||
def create_playlists_table(con: Connection):
|
||||
query = """
|
||||
CREATE TABLE IF NOT EXISTS playlists (
|
||||
|
||||
@@ -6,12 +6,6 @@ def create_db(con: Connection | None = None):
|
||||
create_sessions_table(con)
|
||||
|
||||
|
||||
def drop_sessions_table(con: Connection):
|
||||
query = "DROP TABLE IF EXISTS sessions"
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query)
|
||||
|
||||
|
||||
def create_sessions_table(con: Connection):
|
||||
query = """
|
||||
CREATE TABLE IF NOT EXISTS sessions (
|
||||
|
||||
@@ -2,21 +2,16 @@ import datetime
|
||||
import json
|
||||
from typing import TypedDict
|
||||
|
||||
from folkugat_web.model import IndexedList
|
||||
from folkugat_web.model import search as search_model
|
||||
from folkugat_web.model import temes as model
|
||||
|
||||
TemaRowTuple = tuple[int, str, str, str, str, str, str, str, str, int]
|
||||
TemaRowTuple = tuple[int, str, str, str, str, int]
|
||||
|
||||
|
||||
class TemaRowDict(TypedDict):
|
||||
id: int | None
|
||||
title: str
|
||||
properties: str
|
||||
links: str
|
||||
lyrics: str
|
||||
alternatives: str
|
||||
ngrams: str
|
||||
modification_date: str
|
||||
creation_date: str
|
||||
hidden: int
|
||||
@@ -26,31 +21,24 @@ def tema_to_row(tema: model.Tema) -> TemaRowDict:
|
||||
return {
|
||||
'id': tema.id,
|
||||
'title': tema.title,
|
||||
'properties': json.dumps(list(map(lambda p: p.to_dict(), tema.properties))),
|
||||
'links': json.dumps(list(map(lambda l: l.to_dict(), tema.links))),
|
||||
'lyrics': json.dumps(list(map(lambda l: l.to_dict(), tema.lyrics))),
|
||||
'alternatives': json.dumps(tema.alternatives),
|
||||
'ngrams': json.dumps(tema.ngrams),
|
||||
'modification_date': tema.modification_date.isoformat(),
|
||||
'creation_date': tema.creation_date.isoformat(),
|
||||
'hidden': 1 if tema.hidden else 0,
|
||||
}
|
||||
|
||||
|
||||
def cell_to_ngrams(cell: str) -> search_model.NGrams:
|
||||
return {int(n): ngrams_ for n, ngrams_ in json.loads(cell).items()}
|
||||
def cell_to_ngrams(cell_str: str) -> search_model.NGrams:
|
||||
cell: dict[str, list[str]] = json.loads(cell_str)
|
||||
return {int(n): ngrams_ for n, ngrams_ in cell.items()}
|
||||
|
||||
|
||||
def row_to_tema(row: TemaRowTuple) -> model.Tema:
|
||||
return model.Tema(
|
||||
id=row[0],
|
||||
title=row[1],
|
||||
properties=IndexedList(map(model.Property.from_dict, json.loads(row[2]))),
|
||||
links=IndexedList(map(model.Link.from_dict, json.loads(row[3]))),
|
||||
lyrics=IndexedList(map(model.Lyrics.from_dict, json.loads(row[4]))),
|
||||
alternatives=json.loads(row[5]),
|
||||
ngrams=cell_to_ngrams(row[6]),
|
||||
modification_date=datetime.datetime.fromisoformat(row[7]),
|
||||
creation_date=datetime.datetime.fromisoformat(row[8]),
|
||||
hidden=bool(row[9]),
|
||||
alternatives=json.loads(row[2]),
|
||||
modification_date=datetime.datetime.fromisoformat(row[3]),
|
||||
creation_date=datetime.datetime.fromisoformat(row[4]),
|
||||
hidden=bool(row[5]),
|
||||
)
|
||||
|
||||
@@ -4,12 +4,9 @@ from folkugat_web.dal.sql import Connection, get_connection
|
||||
def create_db(con: Connection | None = None):
|
||||
with get_connection(con) as con:
|
||||
create_temes_table(con)
|
||||
|
||||
|
||||
def drop_temes_table(con: Connection):
|
||||
query = "DROP TABLE IF EXISTS temes"
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query)
|
||||
create_links_table(con)
|
||||
create_lyrics_table(con)
|
||||
create_properties_table(con)
|
||||
|
||||
|
||||
def create_temes_table(con: Connection):
|
||||
@@ -17,11 +14,7 @@ def create_temes_table(con: Connection):
|
||||
CREATE TABLE IF NOT EXISTS temes (
|
||||
id INTEGER PRIMARY KEY,
|
||||
title TEXT NOT NULL,
|
||||
properties TEXT,
|
||||
links TEXT,
|
||||
lyrics TEXT,
|
||||
alternatives TEXT,
|
||||
ngrams TEXT,
|
||||
creation_date TEXT NOT NULL,
|
||||
modification_date TEXT NOT NULL,
|
||||
hidden INTEGER NOT NULL
|
||||
@@ -29,3 +22,47 @@ def create_temes_table(con: Connection):
|
||||
"""
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query)
|
||||
|
||||
|
||||
def create_links_table(con: Connection):
|
||||
query = """
|
||||
CREATE TABLE IF NOT EXISTS tema_links (
|
||||
id INTEGER PRIMARY KEY,
|
||||
tema_id INTEGER,
|
||||
content_type TEXT NOT NULL,
|
||||
link_type TEXT,
|
||||
title TEXT NOT NULL,
|
||||
url TEXT NOT NULL,
|
||||
FOREIGN KEY(tema_id) REFERENCES temes(id) ON DELETE CASCADE
|
||||
)
|
||||
"""
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query)
|
||||
|
||||
|
||||
def create_lyrics_table(con: Connection):
|
||||
query = """
|
||||
CREATE TABLE IF NOT EXISTS tema_lyrics (
|
||||
id INTEGER PRIMARY KEY,
|
||||
tema_id INTEGER,
|
||||
title TEXT NOT NULL,
|
||||
content TEXT NOT NULL,
|
||||
FOREIGN KEY(tema_id) REFERENCES temes(id) ON DELETE CASCADE
|
||||
)
|
||||
"""
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query)
|
||||
|
||||
|
||||
def create_properties_table(con: Connection):
|
||||
query = """
|
||||
CREATE TABLE IF NOT EXISTS tema_properties (
|
||||
id INTEGER PRIMARY KEY,
|
||||
tema_id INTEGER,
|
||||
field TEXT NOT NULL,
|
||||
value TEXT NOT NULL,
|
||||
FOREIGN KEY(tema_id) REFERENCES temes(id) ON DELETE CASCADE
|
||||
)
|
||||
"""
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query)
|
||||
|
||||
137
folkugat_web/dal/sql/temes/links.py
Normal file
137
folkugat_web/dal/sql/temes/links.py
Normal file
@@ -0,0 +1,137 @@
|
||||
from collections.abc import Iterable
|
||||
from typing import TypedDict
|
||||
|
||||
from folkugat_web.dal.sql import Connection, get_connection
|
||||
from folkugat_web.model import temes as model
|
||||
from folkugat_web.utils import map_none
|
||||
|
||||
LinkRowTuple = tuple[int, int, str, str | None, str, str]
|
||||
|
||||
|
||||
class LinkRowDict(TypedDict):
|
||||
id: int | None
|
||||
tema_id: int
|
||||
content_type: str
|
||||
link_type: str | None
|
||||
title: str
|
||||
url: str
|
||||
|
||||
|
||||
def link_to_row(link: model.Link) -> LinkRowDict:
|
||||
return {
|
||||
"id": link.id,
|
||||
"tema_id": link.tema_id,
|
||||
"content_type": link.content_type.value,
|
||||
"link_type": map_none(lambda lt: lt.value, link.link_type),
|
||||
"title": link.title,
|
||||
"url": link.url,
|
||||
}
|
||||
|
||||
|
||||
def row_to_link(row: LinkRowTuple) -> model.Link:
|
||||
return model.Link(
|
||||
id=row[0],
|
||||
tema_id=row[1],
|
||||
content_type=model.ContentType(row[2]),
|
||||
link_type=map_none(model.LinkType, row[3]),
|
||||
title=row[4],
|
||||
url=row[5],
|
||||
)
|
||||
|
||||
|
||||
class QueryData(TypedDict, total=False):
|
||||
id: int
|
||||
tema_id: int
|
||||
|
||||
|
||||
def _filter_clause(
|
||||
link_id: int | None,
|
||||
tema_id: int | None,
|
||||
) -> tuple[str, QueryData]:
|
||||
filter_clauses: list[str] = []
|
||||
filter_data: QueryData = {}
|
||||
|
||||
if link_id is not None:
|
||||
filter_clauses.append("id = :id")
|
||||
filter_data["id"] = link_id
|
||||
|
||||
if tema_id is not None:
|
||||
filter_clauses.append("tema_id = :tema_id")
|
||||
filter_data["tema_id"] = tema_id
|
||||
|
||||
filter_clause = " AND ".join(filter_clauses)
|
||||
return filter_clause, filter_data
|
||||
|
||||
|
||||
def get_links(link_id: int | None = None, tema_id: int | None = None, con: Connection | None = None) -> Iterable[model.Link]:
|
||||
filter_clause, data = _filter_clause(link_id=link_id, tema_id=tema_id)
|
||||
if filter_clause:
|
||||
filter_clause = f"WHERE {filter_clause}"
|
||||
|
||||
query = f"""
|
||||
SELECT
|
||||
id, tema_id, content_type, link_type, title, url
|
||||
FROM tema_links
|
||||
{filter_clause}
|
||||
"""
|
||||
with get_connection(con) as con:
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query, data)
|
||||
return map(row_to_link, cur.fetchall())
|
||||
|
||||
|
||||
def insert_link(link: model.Link, con: Connection | None = None) -> model.Link:
|
||||
data = link_to_row(link)
|
||||
query = f"""
|
||||
INSERT INTO tema_links
|
||||
(id, tema_id, content_type, link_type, title, url)
|
||||
VALUES
|
||||
(:id, :tema_id, :content_type, :link_type, :title, :url)
|
||||
RETURNING *
|
||||
"""
|
||||
with get_connection(con) as con:
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query, data)
|
||||
row: LinkRowTuple = cur.fetchone()
|
||||
return row_to_link(row)
|
||||
|
||||
|
||||
def create_link(tema_id: int, con: Connection | None = None) -> model.Link:
|
||||
new_link = model.Link(
|
||||
id=None,
|
||||
tema_id=tema_id,
|
||||
content_type=model.ContentType.PARTITURA,
|
||||
link_type=None,
|
||||
url="",
|
||||
title="",
|
||||
)
|
||||
return insert_link(new_link, con=con)
|
||||
|
||||
|
||||
def update_link(link: model.Link, con: Connection | None = None):
|
||||
data = link_to_row(link)
|
||||
query = """
|
||||
UPDATE tema_links
|
||||
SET
|
||||
tema_id = :tema_id, content_type = :content_type, link_type = :link_type,
|
||||
title = :title, url = :url
|
||||
WHERE
|
||||
id = :id
|
||||
"""
|
||||
with get_connection(con) as con:
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query, data)
|
||||
|
||||
|
||||
def delete_link(link_id: int, tema_id: int | None = None, con: Connection | None = None):
|
||||
filter_clause, data = _filter_clause(link_id=link_id, tema_id=tema_id)
|
||||
if filter_clause:
|
||||
filter_clause = f"WHERE {filter_clause}"
|
||||
|
||||
query = f"""
|
||||
DELETE FROM tema_links
|
||||
{filter_clause}
|
||||
"""
|
||||
with get_connection(con) as con:
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query, data)
|
||||
127
folkugat_web/dal/sql/temes/lyrics.py
Normal file
127
folkugat_web/dal/sql/temes/lyrics.py
Normal file
@@ -0,0 +1,127 @@
|
||||
from collections.abc import Iterable
|
||||
from typing import TypedDict
|
||||
|
||||
from folkugat_web.dal.sql import Connection, get_connection
|
||||
from folkugat_web.model import temes as model
|
||||
|
||||
LyricRowTuple = tuple[int, int, str, str]
|
||||
|
||||
|
||||
class LyricRowDict(TypedDict):
|
||||
id: int | None
|
||||
tema_id: int
|
||||
title: str
|
||||
content: str
|
||||
|
||||
|
||||
def lyric_to_row(lyric: model.Lyrics) -> LyricRowDict:
|
||||
return {
|
||||
"id": lyric.id,
|
||||
"tema_id": lyric.tema_id,
|
||||
"title": lyric.title,
|
||||
"content": lyric.content,
|
||||
}
|
||||
|
||||
|
||||
def row_to_lyric(row: LyricRowTuple) -> model.Lyrics:
|
||||
return model.Lyrics(
|
||||
id=row[0],
|
||||
tema_id=row[1],
|
||||
title=row[2],
|
||||
content=row[3],
|
||||
)
|
||||
|
||||
|
||||
class QueryData(TypedDict, total=False):
|
||||
id: int
|
||||
tema_id: int
|
||||
|
||||
|
||||
def _filter_clause(
|
||||
lyric_id: int | None,
|
||||
tema_id: int | None,
|
||||
) -> tuple[str, QueryData]:
|
||||
filter_clauses: list[str] = []
|
||||
filter_data: QueryData = {}
|
||||
|
||||
if lyric_id is not None:
|
||||
filter_clauses.append("id = :id")
|
||||
filter_data["id"] = lyric_id
|
||||
|
||||
if tema_id is not None:
|
||||
filter_clauses.append("tema_id = :tema_id")
|
||||
filter_data["tema_id"] = tema_id
|
||||
|
||||
filter_clause = " AND ".join(filter_clauses)
|
||||
return filter_clause, filter_data
|
||||
|
||||
|
||||
def get_lyrics(lyric_id: int | None = None, tema_id: int | None = None, con: Connection | None = None) -> Iterable[model.Lyrics]:
|
||||
filter_clause, data = _filter_clause(lyric_id=lyric_id, tema_id=tema_id)
|
||||
if filter_clause:
|
||||
filter_clause = f"WHERE {filter_clause}"
|
||||
|
||||
query = f"""
|
||||
SELECT
|
||||
id, tema_id, title, content
|
||||
FROM tema_lyrics
|
||||
{filter_clause}
|
||||
"""
|
||||
with get_connection(con) as con:
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query, data)
|
||||
return map(row_to_lyric, cur.fetchall())
|
||||
|
||||
|
||||
def insert_lyric(lyric: model.Lyrics, con: Connection | None = None) -> model.Lyrics:
|
||||
data = lyric_to_row(lyric)
|
||||
query = f"""
|
||||
INSERT INTO tema_lyrics
|
||||
(id, tema_id, title, content)
|
||||
VALUES
|
||||
(:id, :tema_id, :title, :content)
|
||||
RETURNING *
|
||||
"""
|
||||
with get_connection(con) as con:
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query, data)
|
||||
row: LyricRowTuple = cur.fetchone()
|
||||
return row_to_lyric(row)
|
||||
|
||||
|
||||
def create_lyric(tema_id: int, title: str | None = None, con: Connection | None = None) -> model.Lyrics:
|
||||
new_lyric = model.Lyrics(
|
||||
id=None,
|
||||
tema_id=tema_id,
|
||||
title=title or "",
|
||||
content="",
|
||||
)
|
||||
return insert_lyric(new_lyric, con=con)
|
||||
|
||||
|
||||
def update_lyric(lyric: model.Lyrics, con: Connection | None = None):
|
||||
data = lyric_to_row(lyric)
|
||||
query = """
|
||||
UPDATE tema_lyrics
|
||||
SET
|
||||
tema_id = :tema_id, title = :title, content = :content
|
||||
WHERE
|
||||
id = :id
|
||||
"""
|
||||
with get_connection(con) as con:
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query, data)
|
||||
|
||||
|
||||
def delete_lyric(lyric_id: int, tema_id: int | None = None, con: Connection | None = None):
|
||||
filter_clause, data = _filter_clause(lyric_id=lyric_id, tema_id=tema_id)
|
||||
if filter_clause:
|
||||
filter_clause = f"WHERE {filter_clause}"
|
||||
|
||||
query = f"""
|
||||
DELETE FROM tema_lyrics
|
||||
{filter_clause}
|
||||
"""
|
||||
with get_connection(con) as con:
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query, data)
|
||||
127
folkugat_web/dal/sql/temes/properties.py
Normal file
127
folkugat_web/dal/sql/temes/properties.py
Normal file
@@ -0,0 +1,127 @@
|
||||
from collections.abc import Iterable
|
||||
from typing import TypedDict
|
||||
|
||||
from folkugat_web.dal.sql import Connection, get_connection
|
||||
from folkugat_web.model import temes as model
|
||||
|
||||
PropertyRowTuple = tuple[int, int, str, str]
|
||||
|
||||
|
||||
class PropertyRowDict(TypedDict):
|
||||
id: int | None
|
||||
tema_id: int
|
||||
field: str
|
||||
value: str
|
||||
|
||||
|
||||
def property_to_row(property: model.Property) -> PropertyRowDict:
|
||||
return {
|
||||
"id": property.id,
|
||||
"tema_id": property.tema_id,
|
||||
"field": property.field.value,
|
||||
"value": property.value,
|
||||
}
|
||||
|
||||
|
||||
def row_to_property(row: PropertyRowTuple) -> model.Property:
|
||||
return model.Property(
|
||||
id=row[0],
|
||||
tema_id=row[1],
|
||||
field=model.PropertyField(row[2]),
|
||||
value=row[3],
|
||||
)
|
||||
|
||||
|
||||
class QueryData(TypedDict, total=False):
|
||||
id: int
|
||||
tema_id: int
|
||||
|
||||
|
||||
def _filter_clause(
|
||||
property_id: int | None,
|
||||
tema_id: int | None,
|
||||
) -> tuple[str, QueryData]:
|
||||
filter_clauses: list[str] = []
|
||||
filter_data: QueryData = {}
|
||||
|
||||
if property_id is not None:
|
||||
filter_clauses.append("id = :id")
|
||||
filter_data["id"] = property_id
|
||||
|
||||
if tema_id is not None:
|
||||
filter_clauses.append("tema_id = :tema_id")
|
||||
filter_data["tema_id"] = tema_id
|
||||
|
||||
filter_clause = " AND ".join(filter_clauses)
|
||||
return filter_clause, filter_data
|
||||
|
||||
|
||||
def get_properties(property_id: int | None = None, tema_id: int | None = None, con: Connection | None = None) -> Iterable[model.Property]:
|
||||
filter_clause, data = _filter_clause(property_id=property_id, tema_id=tema_id)
|
||||
if filter_clause:
|
||||
filter_clause = f"WHERE {filter_clause}"
|
||||
|
||||
query = f"""
|
||||
SELECT
|
||||
id, tema_id, field, value
|
||||
FROM tema_properties
|
||||
{filter_clause}
|
||||
"""
|
||||
with get_connection(con) as con:
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query, data)
|
||||
return map(row_to_property, cur.fetchall())
|
||||
|
||||
|
||||
def insert_property(property: model.Property, con: Connection | None = None) -> model.Property:
|
||||
data = property_to_row(property)
|
||||
query = f"""
|
||||
INSERT INTO tema_properties
|
||||
(id, tema_id, field, value)
|
||||
VALUES
|
||||
(:id, :tema_id, :field, :value)
|
||||
RETURNING *
|
||||
"""
|
||||
with get_connection(con) as con:
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query, data)
|
||||
row: PropertyRowTuple = cur.fetchone()
|
||||
return row_to_property(row)
|
||||
|
||||
|
||||
def create_property(tema_id: int, field: model.PropertyField | None = None, con: Connection | None = None) -> model.Property:
|
||||
new_property = model.Property(
|
||||
id=None,
|
||||
tema_id=tema_id,
|
||||
field=field or model.PropertyField.AUTOR,
|
||||
value="",
|
||||
)
|
||||
return insert_property(new_property, con=con)
|
||||
|
||||
|
||||
def update_property(property: model.Property, con: Connection | None = None):
|
||||
data = property_to_row(property)
|
||||
query = """
|
||||
UPDATE tema_properties
|
||||
SET
|
||||
tema_id = :tema_id, field = :field, value = :value
|
||||
WHERE
|
||||
id = :id
|
||||
"""
|
||||
with get_connection(con) as con:
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query, data)
|
||||
|
||||
|
||||
def delete_property(property_id: int, tema_id: int | None = None, con: Connection | None = None):
|
||||
filter_clause, data = _filter_clause(property_id=property_id, tema_id=tema_id)
|
||||
if filter_clause:
|
||||
filter_clause = f"WHERE {filter_clause}"
|
||||
|
||||
query = f"""
|
||||
DELETE FROM tema_properties
|
||||
{filter_clause}
|
||||
"""
|
||||
with get_connection(con) as con:
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query, data)
|
||||
@@ -10,8 +10,7 @@ _tema_id_to_ngrams_cache: dict[int, search_model.NGrams] | None = None
|
||||
def get_tema_by_id(tema_id: int, con: Connection | None = None) -> model.Tema | None:
|
||||
query = """
|
||||
SELECT
|
||||
id, title, properties, links, lyrics, alternatives, ngrams,
|
||||
creation_date, modification_date, hidden
|
||||
id, title, alternatives, creation_date, modification_date, hidden
|
||||
FROM temes
|
||||
WHERE id = :id
|
||||
"""
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import json
|
||||
|
||||
from folkugat_web.dal.sql import Connection, get_connection
|
||||
from folkugat_web.model import search as search_model
|
||||
from folkugat_web.model import temes as model
|
||||
|
||||
from . import conversion
|
||||
@@ -8,12 +11,10 @@ from .query import evict_tema_id_to_ngrams_cache
|
||||
def insert_tema(tema: model.Tema, con: Connection | None = None) -> model.Tema:
|
||||
query = """
|
||||
INSERT INTO temes
|
||||
(id, title, properties, links, lyrics, alternatives, ngrams,
|
||||
creation_date, modification_date, hidden)
|
||||
(id, title, alternatives, creation_date, modification_date, hidden)
|
||||
VALUES
|
||||
(:id, :title, :properties, :links, :lyrics, :alternatives, :ngrams,
|
||||
:creation_date, :modification_date, :hidden)
|
||||
RETURNING *
|
||||
(:id, :title, :alternatives, :creation_date, :modification_date, :hidden)
|
||||
RETURNING id, title, alternatives, creation_date, modification_date, hidden
|
||||
"""
|
||||
data = conversion.tema_to_row(tema)
|
||||
with get_connection(con) as con:
|
||||
@@ -28,13 +29,27 @@ def update_tema(tema: model.Tema, con: Connection | None = None):
|
||||
query = """
|
||||
UPDATE temes
|
||||
SET
|
||||
title = :title, properties = :properties, links = :links, lyrics = :lyrics,
|
||||
alternatives = :alternatives, ngrams = :ngrams, creation_date = :creation_date,
|
||||
title = :title, alternatives = :alternatives, creation_date = :creation_date,
|
||||
modification_date = :modification_date, hidden = :hidden
|
||||
WHERE
|
||||
id = :id
|
||||
"""
|
||||
data = conversion.tema_to_row(tema)
|
||||
with get_connection(con) as con:
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query, data)
|
||||
return
|
||||
|
||||
|
||||
def update_ngrams(tema: model.Tema, con: Connection | None = None):
|
||||
query = """
|
||||
UPDATE temes
|
||||
SET
|
||||
ngrams = :ngrams
|
||||
WHERE
|
||||
id = :id
|
||||
"""
|
||||
data = dict(id=tema.id, ngrams=json.dumps(tema.ngrams()))
|
||||
with get_connection(con) as con:
|
||||
cur = con.cursor()
|
||||
_ = cur.execute(query, data)
|
||||
|
||||
Reference in New Issue
Block a user