SQL source

../../../_images/ERD_sql_source.drawio.png


pydantic model crudcreator.source.source.SQLSource.SQLSource[source]

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]

Source parameters.

field sql_inspector: SQLColumnInspector | None = None[source]

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[source]

Completes the “interface” attribute with information that can be retrieved from the SQL database.

Return type:

SQLSource

async get_inspector() SQLColumnInspector[source]

Returns the sql_inspector. Builds it if it has not already been built.

Return type:

SQLColumnInspector



pydantic model crudcreator.source.source.SQLSource.SQLSourceParams[source]
field engine_wrapper: AbstractSQLEngineWrapper [Required][source]

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[source]

Wraps an SQLAlchemy engine.

begin() Iterator[AbstractSQLConnectionWrapper][source]

To be implemented in a child class. Creates a connection and initiates a transaction with the database.

Return type:

Iterator[AbstractSQLConnectionWrapper]

async execute(
req,
)[source]

Executes an SQLAlchemy query.

inspect() AbstractSQLInspectorWrapper[source]

Returns the object wrapping an SQLAlchemy Inspector.

Return type:

AbstractSQLInspectorWrapper



pydantic model crudcreator.adaptator.sql.engine_wrapper.SQLEngineWrapper.SQLEngineSyncWrapper[source]

Wraps a synchronous SQLAlchemy engine (but the interface remains asynchronous).

field engine: Engine [Required][source]
begin() Iterator[SQLConnectionSyncWrapper][source]

Creates a connection and initiates a transaction with the database.

Return type:

Iterator[SQLConnectionSyncWrapper]

inspect() SQLInspectorSyncWrapper[source]

Returns the object wrapping an SQLAlchemy Inspector.

Return type:

SQLInspectorSyncWrapper



pydantic model crudcreator.adaptator.sql.engine_wrapper.SQLEngineWrapper.SQLEngineAsyncWrapper[source]

Wraps a asynchronous SQLAlchemy engine.

field engine: AsyncEngine [Required][source]
begin() Iterator[SQLConnectionAsyncWrapper][source]

Creates a connection and initiates a transaction with the database.

Return type:

Iterator[SQLConnectionAsyncWrapper]

inspect() SQLInspectorAsyncWrapper[source]

Returns the object wrapping an SQLAlchemy Inspector.

Return type:

SQLInspectorAsyncWrapper

Connection wrapper

pydantic model crudcreator.adaptator.sql.engine_wrapper.SQLConnectionWrapper.AbstractSQLConnectionWrapper[source]

Wraps an SQLAlchemy connection.

async execute(
req,
)[source]

Executes an SQLAlchemy query.



pydantic model crudcreator.adaptator.sql.engine_wrapper.SQLConnectionWrapper.SQLConnectionSyncWrapper[source]

Wraps a synchronous SQLAlchemy connection (but the interface remains asynchronous)

field connection: Connection [Required][source]
async execute(
req,
)[source]

Executes an SQLAlchemy query.



pydantic model crudcreator.adaptator.sql.engine_wrapper.SQLConnectionWrapper.SQLConnectionAsyncWrapper[source]

Wraps a aynchronous SQLAlchemy connection.

field connection: AsyncConnection [Required][source]
async execute(
req,
)[source]

Executes an SQLAlchemy query.

Inspector wrapper

pydantic model crudcreator.adaptator.sql.engine_wrapper.SQLInspectorWrapper.AbstractSQLInspectorWrapper[source]

Wraps an SQLAlchemy inspector.

async get_columns(
table_name: str,
schema_name: str,
)[source]
Parameters:
  • table_name (str) –

  • schema_name (str) –

async get_pk_constraint(
table_name: str,
schema_name: str,
)[source]
Parameters:
  • table_name (str) –

  • schema_name (str) –



pydantic model crudcreator.adaptator.sql.engine_wrapper.SQLInspectorWrapper.SQLInspectorSyncWrapper[source]

Wraps an SQLAlchemy inspector from a synchronous engine (but the interface remains asynchronous)

field engine: Engine [Required][source]
async get_columns(
table_name: str,
schema_name: str,
)[source]
Parameters:
  • table_name (str) –

  • schema_name (str) –

async get_pk_constraint(
table_name: str,
schema_name: str,
) dict[str, Any][source]
Parameters:
  • table_name (str) –

  • schema_name (str) –

Return type:

dict[str, Any]



pydantic model crudcreator.adaptator.sql.engine_wrapper.SQLInspectorWrapper.SQLInspectorAsyncWrapper[source]

Wraps an SQLAlchemy inspector from an asynchronous engine

field engine: AsyncEngine [Required][source]
async get_columns(
table_name: str,
schema_name: str,
)[source]
Parameters:
  • table_name (str) –

  • schema_name (str) –

async get_pk_constraint(
table_name: str,
schema_name: str,
) dict[str, Any][source]
Parameters:
  • table_name (str) –

  • schema_name (str) –

Return type:

dict[str, Any]

SQLColumnInspector

pydantic model crudcreator.adaptator.sql.SQLColumnInspector.SQLColumnInspector[source]

A utility for analyzing an SQL table.

field index_column: dict[str, SQLColumn] [Required][source]

Set by the build. An index that associates the name of a column with its information.

field index_sqlalchemy_column: dict[str, Column] [Required][source]

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][source]

Set by the build function. List of table columns and corresponding information.

field list_sqlalchemy_column: list[Column] [Required][source]

Set by the build function. The list of SQLAlchemy columns (used to build queries, for example).

field table: Table [Required][source]

Set by the build function. The SQLAlchemy table.

async static build_from_interface(
sqlalchemy_engine_wrapper: AbstractSQLEngineWrapper,
source_interface: SQLEntityTypeInterface,
)[source]

Builds the inspector.

Parameters:
join_inspector(
other_inspector: SQLColumnInspector,
) SQLColumnInspector[source]

Creates the inspector associated with a virtual table created by joining two other tables.

Parameters:

other_inspector (SQLColumnInspector) –

Return type:

SQLColumnInspector



pydantic model crudcreator.adaptator.sql.SQLColumnInspector.SQLColumn[source]

An instance of this class represents a column information extracted from a SQL database.

field autoincrement: bool | None = None[source]

Is it autoincremented when the row is created?

field default: Any | None = None[source]

The default value for the column.

field name: str | None = None[source]

The column name.

field nullable: bool | None = None[source]

Can the column have null values?

field primary_key: bool | None = None[source]

Is it a primary key.

field type: Any | None = None[source]

Its SQLAlchemy type.