PostgreSQL Database Engine Setup (db/postgres.py)

polar · server/polar/kit/db/postgres.py · python · Apache-2.0
database, lang:python, tag:async

Configures synchronous and asynchronous SQLAlchemy engines, session makers, and read-only session types for PostgreSQL. Reuse when initializing database connections in Python apps.

# Source: https://github.com/polarsource/polar | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
# Provided via justclaw.it.com; keep this notice with the code.
import json
from decimal import Decimal
from typing import Any, NewType

from sqlalchemy import Connection, Engine, event
from sqlalchemy import create_engine as _create_engine
from sqlalchemy.ext.asyncio import AsyncEngine, async_sessionmaker
from sqlalchemy.ext.asyncio import AsyncSession as _AsyncSession
from sqlalchemy.ext.asyncio import (
    create_async_engine as _create_async_engine,
)
from sqlalchemy.orm import Session, sessionmaker

from ..extensions.sqlalchemy import sql

AsyncReadSession = NewType("AsyncReadSession", _AsyncSession)
"""
A type alias for read-only database sessi

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key