Provider API¶
Providers are the adapter layer between NextORM and DBAPI drivers.
Built-in database providers for nextorm.
Importing this package triggers registration of all built-in providers. Currently registered providers:
"sqlite"— sync:SQLiteSyncProvider, async:SQLiteAsyncProvider"postgres"— sync:PostgresSyncProvider, async:PostgresAsyncProvider"mariadb"— sync:MariaDBSyncProvider, async:MariaDBAsyncProvider
Public ABC re-exports¶
The following names are re-exported here for convenience so that library
consumers only need to import from nextorm.providers:
- class nextorm.providers.ProviderBase[source]¶
Bases:
ABCCommon metadata shared by sync and async providers.
- class nextorm.providers.SyncProvider[source]¶
Bases:
ProviderBaseAbstract base for synchronous (DBAPI-2) database providers.
Concrete subclasses must implement
connect()and the abstract methods inherited fromProviderBase.- abstractmethod connect(*args, **kwargs)[source]¶
Open a new synchronous connection.
The returned object must implement
SyncConnection.Parameters¶
- *args / **kwargs:
Driver-specific connection arguments (forwarded from
Database.bind(provider, *args, **kwargs)).
- Parameters:
- Return type:
- abstractmethod execute_ddl(connection, statements)[source]¶
Execute a list of DDL statements on connection.
Provides a hook for providers that need special handling (e.g. SQLite’s
executescriptdisables autocommit).- Parameters:
connection (SyncConnection)
- Return type:
None
- abstractmethod introspect(connection)[source]¶
Read and return the current schema from connection.
Returns a
{table_name: Table}mapping reflecting the tables, columns, and indexes that currently exist in the database. Used bymigrate()to compute the diff between the live schema and the entity-derived target schema.- Parameters:
connection (SyncConnection)
- Return type:
- class nextorm.providers.SyncConnection[source]¶
Bases:
ABCMinimal sync connection interface (DBAPI-2 subset).
- class nextorm.providers.SyncCursor[source]¶
Bases:
ABCMinimal sync cursor interface (DBAPI-2 subset).
- abstract property description: Sequence[tuple[str, Any, Any, Any, Any, Any, Any]] | None¶
Column descriptions from the last executed query.
- abstractmethod executemany(sql, seq_of_parameters)[source]¶
Execute a parameterised statement for each row in seq_of_parameters.
- Parameters:
sql (str)
seq_of_parameters (Sequence[Sequence[Any]])
- Return type:
None
- class nextorm.providers.AsyncProvider[source]¶
Bases:
ProviderBaseAbstract base for async database providers.
Concrete subclasses must implement
connect()and the abstract methods inherited fromProviderBase.- abstractmethod async connect(*args, **kwargs)[source]¶
Open a new async connection.
- Parameters:
- Return type:
- abstractmethod async execute_ddl(connection, statements)[source]¶
Execute a list of DDL statements asynchronously.
- Parameters:
connection (AsyncConnection)
- Return type:
None
- class nextorm.providers.AsyncConnection[source]¶
Bases:
ABCMinimal async connection interface.
- abstractmethod async commit()[source]¶
Commit the current transaction asynchronously.
- Return type:
None
- class nextorm.providers.AsyncCursor[source]¶
Bases:
ABCMinimal async cursor interface (mirrors DBAPI-2 but with
await).- abstract property description: Sequence[tuple[str, Any, Any, Any, Any, Any, Any]] | None¶
Column descriptions from the last executed query.
- abstractmethod async execute(sql, parameters=())[source]¶
Execute a single SQL statement asynchronously.
- abstractmethod async executemany(sql, seq_of_parameters)[source]¶
Execute a parameterised statement for each row asynchronously.
- Parameters:
sql (str)
seq_of_parameters (Sequence[Sequence[Any]])
- Return type:
None
- abstractmethod async fetchmany(size=1)[source]¶
Return up to size rows asynchronously.
- Parameters:
size (int)
- Return type:
Sequence[DbRow]
- nextorm.providers.register_provider(name, *, sync=None, async_=None)[source]¶
Register sync and/or async provider classes under name.
Called at module import time by each provider module.
- Parameters:
name (str)
sync (type[SyncProvider] | None)
async_ (type[AsyncProvider] | None)
- Return type:
None
- nextorm.providers.get_sync_provider(name)[source]¶
Return the sync provider class for name, or raise
ValueError.- Parameters:
name (str)
- Return type: