Initial commit

This commit is contained in:
root
2026-04-29 08:17:35 +00:00
commit ef55253cbd
49 changed files with 3073 additions and 0 deletions

32
app/database.py Normal file
View File

@@ -0,0 +1,32 @@
import asyncpg
import os
from tenacity import retry, stop_after_attempt, wait_fixed
pool: asyncpg.Pool = None
@retry(stop=stop_after_attempt(5), wait=wait_fixed(3))
async def init_db():
global pool
url = os.getenv("DATABASE_URL")
if not url:
raise ValueError("DATABASE_URL nicht gesetzt!")
pool = await asyncpg.create_pool(
dsn=url,
min_size=2,
max_size=10
)
async with pool.acquire() as conn:
await conn.execute("CREATE EXTENSION IF NOT EXISTS vector")
print(f"✅ Datenbank verbunden")
async def close_db():
global pool
if pool:
await pool.close()
async def get_db():
async with pool.acquire() as conn:
yield conn