fix(db): validate cached project connections

This commit is contained in:
2026-07-21 11:35:18 +08:00
parent 9f225374de
commit 50d823ca58
7 changed files with 318 additions and 105 deletions
+19 -15
View File
@@ -1,6 +1,6 @@
from typing import Any
from psycopg.rows import dict_row, Row
from .connection import g_conn_dict as conn
from .connection import project_connection
API_ADD = 'add'
API_UPDATE = 'update'
@@ -83,29 +83,33 @@ class DbChangeSet:
def read(name: str, sql: str) -> Row:
with conn[name].cursor(row_factory=dict_row) as cur:
cur.execute(sql)
row = cur.fetchone()
if row == None:
raise Exception(sql)
return row
with project_connection(name) as conn:
with conn.cursor(row_factory=dict_row) as cur:
cur.execute(sql)
row = cur.fetchone()
if row == None:
raise Exception(sql)
return row
def read_all(name: str, sql: str) -> list[Row]:
with conn[name].cursor(row_factory=dict_row) as cur:
cur.execute(sql)
return cur.fetchall()
with project_connection(name) as conn:
with conn.cursor(row_factory=dict_row) as cur:
cur.execute(sql)
return cur.fetchall()
def try_read(name: str, sql: str) -> Row | None:
with conn[name].cursor(row_factory=dict_row) as cur:
cur.execute(sql)
return cur.fetchone()
with project_connection(name) as conn:
with conn.cursor(row_factory=dict_row) as cur:
cur.execute(sql)
return cur.fetchone()
def write(name: str, sql: str) -> None:
with conn[name].cursor() as cur:
cur.execute(sql)
with project_connection(name) as conn:
with conn.cursor() as cur:
cur.execute(sql)
def get_current_operation(name: str) -> int: