"""
Database connection for the AI Cats Python services.

Uses psycopg2 with connection credentials read exclusively from environment
variables (via config.py / python-dotenv). No credentials are hardcoded.
"""

import psycopg2
import psycopg2.extras
import config


def get_connection():
    """Return a new psycopg2 connection using env-var credentials."""
    return psycopg2.connect(
        host=config.DB_HOST,
        port=config.DB_PORT,
        dbname=config.DB_NAME,
        user=config.DB_USER,
        password=config.DB_PASSWORD,
        cursor_factory=psycopg2.extras.RealDictCursor,
    )
