Initial commit

This commit is contained in:
2026-01-30 13:17:42 +02:00
commit 580d27028b
19 changed files with 335 additions and 0 deletions

1
uv_app/core/__init__.py Normal file
View File

@@ -0,0 +1 @@
"""Core utilities for the application."""

31
uv_app/core/db.py Normal file
View File

@@ -0,0 +1,31 @@
import os
from typing import Optional
import psycopg2
from dotenv import load_dotenv
# Force reload environment variables from .env, ignoring system vars.
load_dotenv(override=True)
DB_HOST = os.getenv("DB_HOST")
DB_PORT = os.getenv("DB_PORT")
DB_NAME = os.getenv("DB_NAME")
DB_USER = os.getenv("DB_USER")
DB_PASSWORD = os.getenv("DB_PASSWORD")
def connect_to_db() -> Optional[psycopg2.extensions.connection]:
"""Establish a connection to the PostgreSQL database."""
try:
return psycopg2.connect(
host=DB_HOST,
port=DB_PORT,
database=DB_NAME,
user=DB_USER,
password=DB_PASSWORD,
# Set the client encoding to UTF-8.
options="-c client_encoding=utf8",
)
except psycopg2.Error as exc:
print(f"Error connecting to PostgreSQL database: {exc}")
return None