graflo.db.sql.provider¶
What a relational source must answer to be introspected.
Introspection needs seven facts about a schema. Everything downstream —
classifying a table as an entity or a relationship, recovering edge endpoints,
mapping columns onto typed fields — is derived from those and is the same for
every dialect. Naming them as a protocol is what lets PostgreSQL keep its
pg_catalog fast path while any other engine arrives through SQLAlchemy
reflection, with one implementation of the logic between them.
Classes¶
SqlMetadataProvider
¶
Bases: Protocol
Schema metadata for one relational database.
schema_name is the namespace to read: a PostgreSQL schema, a MySQL
database, a BigQuery dataset. Implementations accept None and fall back
to their own default.
Source code in graflo/db/sql/provider.py
Methods:¶
get_foreign_keys(table_name, schema_name=None)
¶
Foreign keys, each with column and references_table.
references_column and constraint_name are optional. An engine
that does not enforce foreign keys may still declare them (BigQuery), and
one that enforces them may have none declared — in which case edge
detection falls back to name-based inference.
Source code in graflo/db/sql/provider.py
get_primary_keys(table_name, schema_name=None)
¶
get_table_columns(table_name, schema_name=None)
¶
Columns of table_name.
Each dict carries name and type, and may carry description,
is_nullable, column_default and ordinal_position.
Source code in graflo/db/sql/provider.py
get_table_row_count_estimate(table_name, schema_name=None)
¶
Approximate row count, or None when the engine cannot cheaply say.
get_table_sample_rows(table_name, schema_name=None, limit=5)
¶
A few rows, for column sampling, in a stable order where the engine allows (primary key first). Empty list when unavailable.