Run artifact

build/ReadingList/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", "BookRow"]

@dataclass(frozen=True)
class BookRow:
    id: int
    title: str
    author: str


SCHEMA = Schema(
    tables=(
        Table(name='books', columns=('id', 'title', 'author'), primary_key='id'),
    ),
    operations=(
    Operation(
        identifier='FEATURE-BOOKS-001',
        table='books',
        verb='create',
        inputs=('title', 'author'),
        row=BookRow,
        columns=('id', 'title', 'author'),
    ),
    Operation(
        identifier='FEATURE-BOOKS-002',
        table='books',
        verb='list',
        inputs=(),
        row=BookRow,
        columns=('id', 'title', 'author'),
    ),
    Operation(
        identifier='FEATURE-BOOKS-003',
        table='books',
        verb='get',
        inputs=('id',),
        row=BookRow,
        columns=('id', 'title', 'author'),
    ),
    Operation(
        identifier='FEATURE-BOOKS-004',
        table='books',
        verb='delete',
        inputs=('id',),
        row=None,
        columns=(),
    ),
    ),
)


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)