Initial Commit

This commit is contained in:
belviskhoremk
2026-05-12 00:34:21 +00:00
commit d2dc43b16f
57 changed files with 6056 additions and 0 deletions

42
app/database.py Normal file
View File

@@ -0,0 +1,42 @@
import asyncpg
from app.config import get_settings
_pool: asyncpg.Pool | None = None
async def get_pool() -> asyncpg.Pool:
global _pool
if _pool is None:
settings = get_settings()
_pool = await asyncpg.create_pool(
settings.DATABASE_URL,
min_size=2,
max_size=10,
command_timeout=60,
init=_init_connection,
)
return _pool
async def _init_connection(conn: asyncpg.Connection):
await conn.set_type_codec(
"jsonb",
encoder=lambda v: __import__("json").dumps(v),
decoder=lambda v: __import__("json").loads(v),
schema="pg_catalog",
format="text",
)
await conn.set_type_codec(
"json",
encoder=lambda v: __import__("json").dumps(v),
decoder=lambda v: __import__("json").loads(v),
schema="pg_catalog",
format="text",
)
async def close_pool():
global _pool
if _pool:
await _pool.close()
_pool = None