Run artifact

build/FxRates/persistence/schema.py

"""Generated by Drydock from DATABASE.md. Do not edit; edit the declaration and rebuild.

This module is the declared persistence contract as Python: the tables, the operations each
Blueprint cites, and the row a read or a create returns. It contains no SQL — statements are built by the
driver for the engine in use, so a parameter placeholder never appears here.
"""

from __future__ import annotations

from dataclasses import dataclass

from .db import Database, Operation, Schema, Table

__all__ = ["SCHEMA", "open_database", "RateUpsertOutput", "RatesByDateOutput", "RatesHistoryOutput", "RatesListOutput", "RatesPublicationsThroughOutput"]

@dataclass(frozen=True)
class RateUpsertOutput:
    date: str
    currency: str
    rate: str


@dataclass(frozen=True)
class RatesByDateOutput:
    date: str
    currency: str
    rate: str


@dataclass(frozen=True)
class RatesPublicationsThroughOutput:
    date: str
    currency: str
    rate: str


@dataclass(frozen=True)
class RatesHistoryOutput:
    date: str
    currency: str
    rate: str


@dataclass(frozen=True)
class RatesListOutput:
    date: str
    currency: str
    rate: str


SCHEMA = Schema(
    tables=(
        Table(name='rates', columns=('id', 'date', 'currency', 'rate'), primary_key='id'),
    ),
    operations=(
    Operation(
        identifier='FEATURE-RATE-001',
        table='rates',
        verb='upsert',
        inputs=('date', 'currency', 'rate'),
        row=RateUpsertOutput,
        columns=('date', 'currency', 'rate'),
        match=('date', 'currency'),
        name='upsert',
    ),
    Operation(
        identifier='FEATURE-RATE-002',
        table='rates',
        verb='list',
        inputs=('date',),
        row=RatesByDateOutput,
        columns=('date', 'currency', 'rate'),
        match=(),
        name='by_date',
        order=(('currency', 'asc'),),
    ),
    Operation(
        identifier='FEATURE-RATE-003',
        table='rates',
        verb='list',
        inputs=('requested_date',),
        row=RatesPublicationsThroughOutput,
        columns=('date', 'currency', 'rate'),
        match=(),
        name='publications_through',
        compare=(('requested_date', '<=', 'date'),),
        order=(('date', 'desc'),),
    ),
    Operation(
        identifier='FEATURE-RATE-004',
        table='rates',
        verb='list',
        inputs=('currency', 'start_date', 'end_date'),
        row=RatesHistoryOutput,
        columns=('date', 'currency', 'rate'),
        match=(),
        name='history',
        compare=(('start_date', '>=', 'date'), ('end_date', '<=', 'date')),
        order=(('date', 'asc'),),
    ),
    Operation(
        identifier='FEATURE-RATE-005',
        table='rates',
        verb='list',
        inputs=(),
        row=RatesListOutput,
        columns=('date', 'currency', 'rate'),
        match=(),
        name='list',
    ),
    Operation(
        identifier='FEATURE-RATE-006',
        table='rates',
        verb='delete',
        inputs=('date', 'currency'),
        match=('date', 'currency'),
        name='delete',
    ),
    ),
)


def open_database(dsn: str) -> Database:
    """Open the declared store. The engine is selected from the DSN, not from the build."""
    return Database(dsn, SCHEMA)