SQL source

- pydantic model crudcreator.source.source.SQLSource.SQLSource
Represents a type of entity that is plugged directly into an SQL database. It therefore represents an SQL table (not a database, but a table).
Example of descriptor :
{ "name": "SQLSource", "params": { "engine_wrapper": "$engine_wrapper$" }, "interface": { "name": "book", "fields": [ { "name": "book_id", "is_id_field": true, "can_be_created": true, "can_be_updated": false }, { "name": "title", "is_id_field": false, "can_be_created": true, "can_be_updated": true }, { "name": "public_domain", "is_id_field": false, "can_be_created": true, "can_be_updated": false } ] } }
With “engine_wrapper” a substitution defined, for example, as follows:
from sqlalchemy import create_engine engine = create_engine( f"postgresql+pg8000://{settings.postgres_username}:{settings.postgres_password}@{settings.postgres_host}:{settings.postgres_port}/{settings.postgres_database}", echo=False ) engine_wrapper = SQLEngineSyncWrapper(engine=engine)
- field params: SQLSourceParams [Required]
Source parameters.
- field sql_inspector: SQLColumnInspector | None = None
A utility that allows us to analyze the source (among other things, to complete the interface attribute). Will be built by get_inspector. Will be used by proxies built on top of this one.
- async complete() SQLSource
Completes the “interface” attribute with information that can be retrieved from the SQL database.
- Return type:
- async get_inspector() SQLColumnInspector
Returns the sql_inspector. Builds it if it has not already been built.
- Return type:
- pydantic model crudcreator.source.source.SQLSource.SQLSourceParams
- field engine_wrapper: AbstractSQLEngineWrapper [Required]
L’objet qui permet à CRUDCreator d’interagir avec la base de données SQL.
Engine wrapper
- pydantic model crudcreator.adaptator.sql.engine_wrapper.SQLEngineWrapper.AbstractSQLEngineWrapper
Wraps an SQLAlchemy engine.
- begin() Iterator[AbstractSQLConnectionWrapper]
To be implemented in a child class. Creates a connection and initiates a transaction with the database.
- Return type:
Iterator[AbstractSQLConnectionWrapper]
- async execute(
- req,
Executes an SQLAlchemy query.
- inspect() AbstractSQLInspectorWrapper
Returns the object wrapping an SQLAlchemy Inspector.
- Return type:
- pydantic model crudcreator.adaptator.sql.engine_wrapper.SQLEngineWrapper.SQLEngineSyncWrapper
Wraps a synchronous SQLAlchemy engine (but the interface remains asynchronous).
- field engine: Engine [Required]
- begin() Iterator[SQLConnectionSyncWrapper]
Creates a connection and initiates a transaction with the database.
- Return type:
Iterator[SQLConnectionSyncWrapper]
- inspect() SQLInspectorSyncWrapper
Returns the object wrapping an SQLAlchemy Inspector.
- Return type:
- pydantic model crudcreator.adaptator.sql.engine_wrapper.SQLEngineWrapper.SQLEngineAsyncWrapper
Wraps a asynchronous SQLAlchemy engine.
- field engine: AsyncEngine [Required]
- begin() Iterator[SQLConnectionAsyncWrapper]
Creates a connection and initiates a transaction with the database.
- Return type:
Iterator[SQLConnectionAsyncWrapper]
- inspect() SQLInspectorAsyncWrapper
Returns the object wrapping an SQLAlchemy Inspector.
- Return type:
Connection wrapper
- pydantic model crudcreator.adaptator.sql.engine_wrapper.SQLConnectionWrapper.AbstractSQLConnectionWrapper
Wraps an SQLAlchemy connection.
- async execute(
- req,
Executes an SQLAlchemy query.
- pydantic model crudcreator.adaptator.sql.engine_wrapper.SQLConnectionWrapper.SQLConnectionSyncWrapper
Wraps a synchronous SQLAlchemy connection (but the interface remains asynchronous)
- field connection: Connection [Required]
- async execute(
- req,
Executes an SQLAlchemy query.
Inspector wrapper
- pydantic model crudcreator.adaptator.sql.engine_wrapper.SQLInspectorWrapper.AbstractSQLInspectorWrapper
Wraps an SQLAlchemy inspector.
- async get_columns(
- table_name: str,
- schema_name: str,
- Parameters:
table_name (str) –
schema_name (str) –
- async get_pk_constraint(
- table_name: str,
- schema_name: str,
- Parameters:
table_name (str) –
schema_name (str) –
- pydantic model crudcreator.adaptator.sql.engine_wrapper.SQLInspectorWrapper.SQLInspectorSyncWrapper
Wraps an SQLAlchemy inspector from a synchronous engine (but the interface remains asynchronous)
- field engine: Engine [Required]
- async get_columns(
- table_name: str,
- schema_name: str,
- Parameters:
table_name (str) –
schema_name (str) –
- async get_pk_constraint(
- table_name: str,
- schema_name: str,
- Parameters:
table_name (str) –
schema_name (str) –
- Return type:
dict[str, Any]
- pydantic model crudcreator.adaptator.sql.engine_wrapper.SQLInspectorWrapper.SQLInspectorAsyncWrapper
Wraps an SQLAlchemy inspector from an asynchronous engine
- field engine: AsyncEngine [Required]
- async get_columns(
- table_name: str,
- schema_name: str,
- Parameters:
table_name (str) –
schema_name (str) –
- async get_pk_constraint(
- table_name: str,
- schema_name: str,
- Parameters:
table_name (str) –
schema_name (str) –
- Return type:
dict[str, Any]
SQLColumnInspector
- pydantic model crudcreator.adaptator.sql.SQLColumnInspector.SQLColumnInspector
A utility for analyzing an SQL table.
- field index_column: dict[str, SQLColumn] [Required]
Set by the build. An index that associates the name of a column with its information.
- field index_sqlalchemy_column: dict[str, Column] [Required]
Set by the build function. An index that associates the name of a column with the corresponding SQLAlchemy column.
- field list_column: list[SQLColumn] [Required]
Set by the build function. List of table columns and corresponding information.
- field list_sqlalchemy_column: list[Column] [Required]
Set by the build function. The list of SQLAlchemy columns (used to build queries, for example).
- field table: Table [Required]
Set by the build function. The SQLAlchemy table.
- async static build_from_interface(
- sqlalchemy_engine_wrapper: AbstractSQLEngineWrapper,
- source_interface: SQLEntityTypeInterface,
Builds the inspector.
- Parameters:
sqlalchemy_engine_wrapper (AbstractSQLEngineWrapper) –
source_interface (SQLEntityTypeInterface) –
- join_inspector(
- other_inspector: SQLColumnInspector,
Creates the inspector associated with a virtual table created by joining two other tables.
- Parameters:
other_inspector (SQLColumnInspector) –
- Return type:
- pydantic model crudcreator.adaptator.sql.SQLColumnInspector.SQLColumn
An instance of this class represents a column information extracted from a SQL database.
- field autoincrement: bool | None = None
Is it autoincremented when the row is created?
- field default: Any | None = None
The default value for the column.
- field name: str | None = None
The column name.
- field nullable: bool | None = None
Can the column have null values?
- field primary_key: bool | None = None
Is it a primary key.
- field type: Any | None = None
Its SQLAlchemy type.