17 lines
570 B
Python
17 lines
570 B
Python
# app/db/queries/queries.py
|
||
import pathlib
|
||
import aiosql
|
||
|
||
_SQL_DIR = pathlib.Path(__file__).parent / "sql"
|
||
|
||
def _load_all_sql_text_utf8() -> str:
|
||
# 统一用 UTF-8 读取 sql 目录下所有 .sql 文件(按文件名排序)
|
||
parts: list[str] = []
|
||
for p in sorted(_SQL_DIR.glob("*.sql")):
|
||
parts.append(p.read_text(encoding="utf-8"))
|
||
parts.append("\n")
|
||
return "".join(parts)
|
||
|
||
# 用 from_str,而不是 from_path(from_path 会按系统默认编码读取)
|
||
queries = aiosql.from_str(_load_all_sql_text_utf8(), driver_adapter="asyncpg")
|