Skip to content

OrmTable

ormdantic.generator._table.OrmTableGenerator

OrmTableGenerator(engine, metadata, table_map)

Initialize OrmTableGenerator.

PARAMETER DESCRIPTION
engine

TYPE: AsyncEngine

metadata

TYPE: MetaData

table_map

TYPE: Map

Source code in ormdantic/generator/_table.py
def __init__(
    self,
    engine: AsyncEngine,
    metadata: MetaData,
    table_map: Map,
) -> None:
    """Initialize OrmTableGenerator."""
    self._engine = engine
    self._metadata = metadata
    self._table_map = table_map
    self._tables: list[str] = []

init async

init()

Generate SQL Alchemy tables.

Source code in ormdantic/generator/_table.py
async def init(self) -> None:
    """Generate SQL Alchemy tables."""
    for tablename, table_data in self._table_map.name_to_data.items():
        unique_constraints = (
            UniqueConstraint(*cols, name=f"{'_'.join(cols)}_constraint")
            for cols in table_data.unique_constraints
        )
        self._tables.append(tablename)
        Table(
            tablename,
            self._metadata,
            *self._get_columns(table_data),
            *unique_constraints,
        )
    async with self._engine.begin() as conn:
        await conn.run_sync(self._metadata.create_all)