Use basedpyright refactor
This commit is contained in:
@@ -1,12 +1,10 @@
|
||||
from typing import Optional
|
||||
|
||||
from folkugat_web.dal.sql import Connection, get_connection
|
||||
from folkugat_web.model import playlists as model
|
||||
|
||||
from ._conversion import playlist_entry_to_row, row_to_playlist_entry
|
||||
from . import conversion
|
||||
|
||||
|
||||
def insert_playlist_entry(pl_entry: model.PlaylistEntry, con: Optional[Connection] = None) -> model.PlaylistEntry:
|
||||
def insert_playlist_entry(pl_entry: model.PlaylistEntry, con: Connection | None = None) -> model.PlaylistEntry:
|
||||
query = """
|
||||
INSERT INTO playlists
|
||||
(id, session_id, set_id, tema_id)
|
||||
@@ -14,15 +12,15 @@ def insert_playlist_entry(pl_entry: model.PlaylistEntry, con: Optional[Connectio
|
||||
(:id, :session_id, :set_id, :tema_id)
|
||||
RETURNING *
|
||||
"""
|
||||
data = playlist_entry_to_row(pl_entry)
|
||||
data = conversion.playlist_entry_to_row(pl_entry)
|
||||
with get_connection(con) as con:
|
||||
cur = con.cursor()
|
||||
cur.execute(query, data)
|
||||
row = cur.fetchone()
|
||||
return row_to_playlist_entry(row)
|
||||
_ = cur.execute(query, data)
|
||||
row: conversion.PlaylistRowTuple = cur.fetchone()
|
||||
return conversion.row_to_playlist_entry(row)
|
||||
|
||||
|
||||
def update_playlist_entry(entry: model.PlaylistEntry, con: Optional[Connection] = None):
|
||||
def update_playlist_entry(entry: model.PlaylistEntry, con: Connection | None = None):
|
||||
query = """
|
||||
UPDATE playlists
|
||||
SET
|
||||
@@ -30,14 +28,14 @@ def update_playlist_entry(entry: model.PlaylistEntry, con: Optional[Connection]
|
||||
WHERE
|
||||
id = :id
|
||||
"""
|
||||
data = playlist_entry_to_row(entry)
|
||||
data = conversion.playlist_entry_to_row(entry)
|
||||
with get_connection(con) as con:
|
||||
cur = con.cursor()
|
||||
cur.execute(query, data)
|
||||
_ = cur.execute(query, data)
|
||||
return
|
||||
|
||||
|
||||
def delete_playlist_entry(entry_id: int, con: Optional[Connection] = None):
|
||||
def delete_playlist_entry(entry_id: int, con: Connection | None = None):
|
||||
query = """
|
||||
DELETE FROM playlists
|
||||
WHERE id = :id
|
||||
@@ -45,11 +43,11 @@ def delete_playlist_entry(entry_id: int, con: Optional[Connection] = None):
|
||||
data = dict(id=entry_id)
|
||||
with get_connection(con) as con:
|
||||
cur = con.cursor()
|
||||
cur.execute(query, data)
|
||||
_ = cur.execute(query, data)
|
||||
return
|
||||
|
||||
|
||||
def delete_playlist_set(session_id: int, set_id: int, con: Optional[Connection] = None):
|
||||
def delete_playlist_set(session_id: int, set_id: int, con: Connection | None = None):
|
||||
query = """
|
||||
DELETE FROM playlists
|
||||
WHERE session_id = :session_id AND set_id = :set_id
|
||||
@@ -57,5 +55,5 @@ def delete_playlist_set(session_id: int, set_id: int, con: Optional[Connection]
|
||||
data = dict(session_id=session_id, set_id=set_id)
|
||||
with get_connection(con) as con:
|
||||
cur = con.cursor()
|
||||
cur.execute(query, data)
|
||||
_ = cur.execute(query, data)
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user