This commit is contained in:
2026-05-11 22:08:50 +03:00
commit 9f4bf13276
11 changed files with 618 additions and 0 deletions

19
backend/db.py Normal file
View File

@@ -0,0 +1,19 @@
# backend/db.py
import os
from psycopg2 import pool
from dotenv import load_dotenv
load_dotenv()
DATABASE_URL = os.getenv('DATABASE_URL')
# Initialise a connection pool (min 1, max 10 connections)
postgres_pool = pool.ThreadedConnectionPool(1, 10, dsn=DATABASE_URL)
def get_db_connection():
"""Return a connection from the pool. Caller must close it after use."""
return postgres_pool.getconn()
def release_db_connection(conn):
"""Return the connection to the pool."""
postgres_pool.putconn(conn)