Use basedpyright refactor
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
from typing import Optional
|
||||
|
||||
from folkugat_web.dal.sql import Connection, get_connection
|
||||
from folkugat_web.model import temes as model
|
||||
|
||||
from ._conversion import row_to_tema, tema_to_row
|
||||
from . import conversion
|
||||
from .query import evict_tema_id_to_ngrams_cache
|
||||
|
||||
|
||||
def insert_tema(tema: model.Tema, con: Optional[Connection] = None) -> model.Tema:
|
||||
def insert_tema(tema: model.Tema, con: Connection | None = None) -> model.Tema:
|
||||
query = """
|
||||
INSERT INTO temes
|
||||
(id, title, properties, links, lyrics, alternatives, ngrams,
|
||||
@@ -17,16 +15,16 @@ def insert_tema(tema: model.Tema, con: Optional[Connection] = None) -> model.Tem
|
||||
:creation_date, :modification_date, :hidden)
|
||||
RETURNING *
|
||||
"""
|
||||
data = tema_to_row(tema)
|
||||
data = conversion.tema_to_row(tema)
|
||||
with get_connection(con) as con:
|
||||
cur = con.cursor()
|
||||
cur.execute(query, data)
|
||||
row = cur.fetchone()
|
||||
_ = cur.execute(query, data)
|
||||
row: conversion.TemaRowTuple = cur.fetchone()
|
||||
evict_tema_id_to_ngrams_cache()
|
||||
return row_to_tema(row)
|
||||
return conversion.row_to_tema(row)
|
||||
|
||||
|
||||
def update_tema(tema: model.Tema, con: Optional[Connection] = None):
|
||||
def update_tema(tema: model.Tema, con: Connection | None = None):
|
||||
query = """
|
||||
UPDATE temes
|
||||
SET
|
||||
@@ -36,15 +34,15 @@ def update_tema(tema: model.Tema, con: Optional[Connection] = None):
|
||||
WHERE
|
||||
id = :id
|
||||
"""
|
||||
data = tema_to_row(tema)
|
||||
data = conversion.tema_to_row(tema)
|
||||
with get_connection(con) as con:
|
||||
cur = con.cursor()
|
||||
cur.execute(query, data)
|
||||
_ = cur.execute(query, data)
|
||||
evict_tema_id_to_ngrams_cache()
|
||||
return
|
||||
|
||||
|
||||
def delete_tema(tema_id: int, con: Optional[Connection] = None):
|
||||
def delete_tema(tema_id: int, con: Connection | None = None):
|
||||
query = """
|
||||
DELETE FROM temes
|
||||
WHERE id = :id
|
||||
@@ -52,6 +50,6 @@ def delete_tema(tema_id: int, con: Optional[Connection] = None):
|
||||
data = dict(id=tema_id)
|
||||
with get_connection(con) as con:
|
||||
cur = con.cursor()
|
||||
cur.execute(query, data)
|
||||
_ = cur.execute(query, data)
|
||||
evict_tema_id_to_ngrams_cache()
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user