MetaDataBuilder

class felis.metadata.MetaDataBuilder(schema, apply_schema_to_metadata=True, apply_schema_to_tables=True, ignore_constraints=False)

Bases: object

Build a SQLAlchemy metadata object from a Felis schema.

Parameters:
  • schema (Schema) – The schema object from which to build the SQLAlchemy metadata.

  • apply_schema_to_metadata (bool, default: True) – Whether to apply the schema name to the metadata object.

  • apply_schema_to_tables (bool, default: True) – Whether to apply the schema name to the tables.

  • ignore_constraints (bool, default: False) – Whether to ignore constraints when building the metadata.

Methods Summary

build()

Build the SQLAlchemy tables and constraints from the schema.

build_column(column_obj)

Build a SQLAlchemy Column from a Felis column object.

build_constraint(constraint_obj)

Build a SQLAlchemy Constraint from a Felis constraint.

build_constraints()

Build the SQLAlchemy constraints from the Felis schema and append them to the associated table in the metadata.

build_index(index_obj)

Build a SQLAlchemy Index from a Felis Index.

build_primary_key(primary_key_columns)

Build a SQAlchemy PrimaryKeyConstraint from a single column ID or a list of them.

build_table(table_obj)

Build a SQLAlchemy Table from a Felis table and add it to the metadata.

build_tables()

Build the SQLAlchemy tables from the schema.

Methods Documentation

build()

Build the SQLAlchemy tables and constraints from the schema.

Notes

This first builds the tables and then makes a second pass to build the constraints. This is necessary because the constraints may reference objects that are not yet created when the tables are built.

Returns:

The SQLAlchemy metadata object.

Return type:

MetaData

build_column(column_obj)

Build a SQLAlchemy Column from a Felis column object.

Parameters:

column_obj (Column) – The column object from which to build the SQLAlchemy column.

Returns:

The SQLAlchemy column object.

Return type:

Column

build_constraint(constraint_obj)

Build a SQLAlchemy Constraint from a Felis constraint.

Parameters:

constraint_obj (Constraint) – The Felis object from which to build the constraint.

Returns:

The SQLAlchemy constraint object.

Return type:

Constraint

Raises:
  • ValueError – If the constraint type is not recognized.

  • TypeError – If the constraint object is not the expected type.

build_constraints()

Build the SQLAlchemy constraints from the Felis schema and append them to the associated table in the metadata.

Return type:

None

Notes

This is performed as a separate step after building the tables so that all the referenced objects in the constraints will be present and can be looked up by their ID.

build_index(index_obj)

Build a SQLAlchemy Index from a Felis Index.

Parameters:

index_obj (Index) – The Felis object from which to build the SQLAlchemy index.

Returns:

The SQLAlchemy index object.

Return type:

Index

build_primary_key(primary_key_columns)

Build a SQAlchemy PrimaryKeyConstraint from a single column ID or a list of them.

Parameters:

primary_key_columns (str | list[str]) – The column ID or list of column IDs from which to build the primary key.

Returns:

The SQLAlchemy primary key constraint object.

Return type:

PrimaryKeyConstraint

Notes

The primary_key_columns is a string or a list of strings representing IDs which will be used to find the columnn objects in the builder’s internal ID map.

build_table(table_obj)

Build a SQLAlchemy Table from a Felis table and add it to the metadata.

Parameters:

table_obj (Table) – The Felis table object from which to build the SQLAlchemy table.

Return type:

None

Notes

Several MySQL table options, including the engine and charset, are handled by adding annotations to the table. This is not needed for Postgres, as Felis does not support any table options for this dialect.

build_tables()

Build the SQLAlchemy tables from the schema.

Return type:

None