MetaDataBuilder

class felis.metadata.MetaDataBuilder(schema, apply_schema_to_metadata=True, ignore_constraints=False, table_name_postfix='', skip_indexes=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.

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

  • table_name_postfix (str, default: '') – A string to append to the table names when building the metadata.

  • skip_indexes (bool, default: False) – Skip indexes 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(table_obj, 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(table_obj, index_obj)

Build a SQLAlchemy Index from a Felis Index.

build_indexes()

Build the SQLAlchemy indexes from the Felis schema and add them to the associated table in the metadata.

build_primary_key(table_obj)

Build a SQLAlchemy PrimaryKeyConstraint from a Felis table's primary key.

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(table_obj, constraint_obj)

Build a SQLAlchemy Constraint from a Felis constraint.

Parameters:
  • table_obj (Table) – The Felis table that owns the constraint. It is used to resolve the constraint’s source column references.

  • 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 resolved.

build_index(table_obj, index_obj)

Build a SQLAlchemy Index from a Felis Index.

Parameters:
  • table_obj (Table) – The Felis table that owns the index. It is used to resolve the index’s column references.

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

Returns:

The SQLAlchemy index object.

Return type:

Index

build_indexes()

Build the SQLAlchemy indexes from the Felis schema and add them to the associated table in the metadata.

Return type:

None

build_primary_key(table_obj)

Build a SQLAlchemy PrimaryKeyConstraint from a Felis table’s primary key.

Parameters:

table_obj (Table) – The Felis table that owns the primary key. Its primary_key field provides the column reference or list of column references from which to build the primary key, and is also used to resolve those references.

Returns:

The SQLAlchemy primary key constraint object.

Return type:

PrimaryKeyConstraint

Notes

Each entry in table_obj.primary_key is a reference which is resolved within table_obj by column name, falling back to column ID for backward compatibility. Primary key references are resolved within the owning table rather than against the schema-wide 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