architxt.database.loader.sql#
Functions
|
Create a tree representation for a table with its columns and data. |
|
Handle the current data for a table and its referred table. |
|
Retrieve tables that are part of a cycle in the database relations. |
|
Generate an object identifier based on the DB namespace, the name of the table/relation, and primary key values. |
|
Retrieve the root tables in the database by identifying tables that are not referenced as foreign keys. |
|
Check if a table is a many-to-many association table. |
|
Parse a row of an association table into trees. |
|
Parse a row of a table into trees. |
|
Read the database instance as a tree. |
|
Process the relations of a given table, retrieve data, and construct tree representations. |
|
Process the relations of a table that is not referenced by any other tables. |
- architxt.database.loader.sql.build_group(table, row, namespace)[source]#
Create a tree representation for a table with its columns and data.
- architxt.database.loader.sql.build_relation(left_table, right_table, left_row, right_row, namespace, node_data=None, name='')[source]#
Handle the current data for a table and its referred table.
- Parameters:
left_table (
Table
) – The left table of the relation.right_table (
Table
) – The right table of the relation.left_row (
Row
) – The left table row of the relation.right_row (
Row
) – The right table row of the relation.namespace (
UUID
) – The database namespace to use for the object identifier.node_data (
Optional
[dict
[str
,Any
]]) – Dictionary containing relation data.name (
str
) – The name of the relation, if not set, it will be automatically generated.
- Return type:
- Returns:
The tree of the relation.
- architxt.database.loader.sql.get_cycle_tables(tables)[source]#
Retrieve tables that are part of a cycle in the database relations.
If multiple tables are in a cycle, only the one with the maximum foreign keys is returned.
- architxt.database.loader.sql.get_oid(namespace, name, data)[source]#
Generate an object identifier based on the DB namespace, the name of the table/relation, and primary key values.
The namespace hierarchy follows this structure:
Database Namespace └── Table/Relation Namespace (uuid5(db_namespace, name)) └── Record OID (uuid5(table_namespace, sorted_data))
- Parameters:
- Return type:
- Returns:
UUID5 generated from the namespace and combined name/data
- architxt.database.loader.sql.get_root_tables(tables)[source]#
Retrieve the root tables in the database by identifying tables that are not referenced as foreign keys.
- architxt.database.loader.sql.is_association_table(table)[source]#
Check if a table is a many-to-many association table.
- architxt.database.loader.sql.parse_association_table(table, row, *, conn, namespace)[source]#
Parse a row of an association table into trees.
The table is discarded and represented only as a relation between the two linked tables.
- Parameters:
table (
Table
) – The table to process.row (
Row
) – A row of the table.conn (
Connection
) – SQLAlchemy connection.namespace (
UUID
) – The database namespace to use for the object identifier.
- Yield:
Trees representing the relations and data for the table.
- Return type:
- architxt.database.loader.sql.parse_table(table, row, *, conn, namespace, _visited_links=None)[source]#
Parse a row of a table into trees.
- Parameters:
table (
Table
) – The table to process.row (
Row
) – A row of the table.conn (
Connection
) – SQLAlchemy connection.namespace (
UUID
) – The database namespace to use for the object identifier._visited_links (
Optional
[set
[ForeignKey
]]) – Set of visited relations to avoid cycles.
- Yield:
Trees representing the relations and data for the table.
- Return type:
- architxt.database.loader.sql.read_sql(conn, *, simplify_association=True, search_all_instances=False, sample=0)[source]#
Read the database instance as a tree.
- Parameters:
conn (
Connection
) – SQLAlchemy connection to the database.simplify_association (
bool
) – Flag to simplify non-attributed association tables.search_all_instances (
bool
) – Flag to search for all instances of the database.sample (
int
) – Number of samples for each table to get.
- Return type:
- Returns:
A list of trees representing the database.
- architxt.database.loader.sql.read_table(table, *, conn, namespace, simplify_association=False, sample=0)[source]#
Process the relations of a given table, retrieve data, and construct tree representations.
- Parameters:
table (
Table
) – The table to process.conn (
Connection
) – SQLAlchemy connection.namespace (
UUID
) – The database namespace to use for the object identifier.simplify_association (
bool
) – Flag to simplify non-attributed association tables.sample (
int
) – Number of samples for each table to get.
- Return type:
- Returns:
A list of trees representing the relations and data for the table.
- architxt.database.loader.sql.read_unreferenced_table(foreign_key, *, conn, namespace, sample=0, _visited_links=None)[source]#
Process the relations of a table that is not referenced by any other tables.
- Parameters:
foreign_key (
ForeignKey
) – The foreign key to process.conn (
Connection
) – SQLAlchemy connection.namespace (
UUID
) – The database namespace to use for the object identifier.sample (
int
) – Number of samples for each table to get._visited_links (
Optional
[set
[ForeignKey
]]) – Set of visited relations to avoid cycles.
- Return type:
- Returns:
A list of trees representing the relations and data for the table.