2025-12-04 10:04:21 +08:00

17 lines
570 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 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_pathfrom_path 会按系统默认编码读取)
queries = aiosql.from_str(_load_all_sql_text_utf8(), driver_adapter="asyncpg")