MetaDataBuilder¶
- class felis.metadata.MetaDataBuilder(schema, apply_schema_to_metadata=True, ignore_constraints=False, table_name_postfix='', skip_indexes=False)¶
Bases:
objectBuild 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
Columnfrom a Felis column object.build_constraint(table_obj, constraint_obj)Build a SQLAlchemy
Constraintfrom a Felis constraint.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
Indexfrom a FelisIndex.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
PrimaryKeyConstraintfrom a Felis table's primary key.build_table(table_obj)Build a SQLAlchemy
Tablefrom a Felis table and add it to the metadata.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:
- build_column(column_obj)¶
Build a SQLAlchemy
Columnfrom a Felis column object.
- build_constraint(table_obj, constraint_obj)¶
Build a SQLAlchemy
Constraintfrom 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:
- 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:
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_indexes()¶
Build the SQLAlchemy indexes from the Felis schema and add them to the associated table in the metadata.
- Return type:
- build_primary_key(table_obj)¶
Build a SQLAlchemy
PrimaryKeyConstraintfrom a Felis table’s primary key.- Parameters:
table_obj (
Table) – The Felis table that owns the primary key. Itsprimary_keyfield 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:
Notes
Each entry in
table_obj.primary_keyis a reference which is resolved withintable_objby 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
Tablefrom 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:
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.