MetaDataBuilder¶
- class felis.metadata.MetaDataBuilder(schema, apply_schema_to_metadata=True, apply_schema_to_tables=True)¶
Bases:
object
Build a SQLAlchemy metadata object from a Felis schema.
- Parameters:
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 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 FelisIndex
.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 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
Column
from a Felis column object.
- 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:
- 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 looked up by their ID.
- 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:
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:
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.