Managers
plateforme.core.database.base
This module defines the DatabaseManager
class for controlling database
operations. It provides methods for managing database engine connections and
routing operations using DatabaseRouter
interfaces for multi-database
environment scenario within the Plateforme framework.
DatabaseManager
DatabaseManager(
urls: EngineMap,
routers: list[DatabaseRouter] | None = None,
)
A utility class for managing database engine connections.
Initialize the engine manager.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
urls
|
EngineMap
|
A dictionary of database engine URLs to be managed. |
required |
routers
|
list[DatabaseRouter] | None
|
A list of database routers to be used for routing operations. Defaults to an empty list. |
None
|
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/base.py
get_engine
get_engine(
resource: type[Any] | None = None,
async_mode: bool = False,
operation_mode: Literal["read", "write"] | None = None,
**kwargs: Any,
) -> AsyncEngine | Engine
Give a suggestion for the standard engine to use.
Suggest the standard engine that should be used for read and write operations on a given resource clase.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resource
|
type[Any] | None
|
The resource class. Defaults to |
None
|
async_mode
|
bool
|
Whether to return an async engine or a sync engine.
Defaults to |
False
|
operation_mode
|
Literal['read', 'write'] | None
|
The mode of operation either |
None
|
**kwargs
|
Any
|
Additional information to assist in selecting an engine. |
{}
|
Returns:
Type | Description |
---|---|
AsyncEngine | Engine
|
Either an async engine or a sync engine depending on the chosen |
AsyncEngine | Engine
|
async mode. Defaults to sync engine. |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/base.py
get_read_engine
get_read_engine(
resource: type[Any] | None = None,
async_mode: bool = False,
**kwargs: Any,
) -> AsyncEngine | Engine
Give a suggestion for the engine to use for read operations.
Suggest the engine that should be used for read operations on a given resource clase.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resource
|
type[Any] | None
|
The resource class. |
None
|
async_mode
|
bool
|
Whether to return an async engine or a sync engine.
Defaults to |
False
|
**kwargs
|
Any
|
Additional information to assist in selecting an engine. |
{}
|
Returns:
Type | Description |
---|---|
AsyncEngine | Engine
|
An engine alias if a suggestion is made, else |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/base.py
get_write_engine
get_write_engine(
resource: type[Any] | None = None,
async_mode: bool = False,
**kwargs: Any,
) -> AsyncEngine | Engine
Give a suggestion for the engine to use for write operations.
Suggest the engine that should be used for write operations on a given resource clase.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
resource
|
type[Any] | None
|
The resource class. |
None
|
async_mode
|
bool
|
Whether to return an async engine or a sync engine.
Defaults to |
False
|
**kwargs
|
Any
|
Additional information to assist in selecting an engine. |
{}
|
Returns:
Type | Description |
---|---|
AsyncEngine | Engine
|
An engine alias if a suggestion is made, else |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/base.py
is_migration_allowed
Flag whether a migration operation is allowed to run.
Determine if the migration operation is allowed to run on the specified database engine alias.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
engine
|
str
|
The database engine alias. |
required |
package
|
str
|
The name of the package being migrated. |
required |
**kwargs
|
Any
|
Additional information to assist in making a decision. |
{}
|
Returns:
Type | Description |
---|---|
bool
|
|
bool
|
|
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/base.py
This module defines the DatabaseManager
class for controlling database
operations. It provides methods for managing database engine connections and
routing operations using DatabaseRouter
interfaces for multi-database
environment scenario within the Plateforme framework.
MissingGreenlet
Bases: InvalidRequestError
Error raised by the async greenlet await_ if called while not inside the greenlet spawn context.
Source code in .venv/lib/python3.12/site-packages/sqlalchemy/exc.py
inspect
inspect(
subject: _InspectableProtocol[_IN],
raiseerr: bool = True,
) -> _IN
inspect(
subject: Inspectable[_IN], raiseerr: bool = True
) -> _IN
Produce an inspection object for the given target.
The returned value in some cases may be the
same object as the one given, such as if a
:class:_orm.Mapper
object is passed. In other
cases, it will be an instance of the registered
inspection type for the given object, such as
if an :class:_engine.Engine
is passed, an
:class:_reflection.Inspector
object is returned.
:param subject: the subject to be inspected.
:param raiseerr: When True
, if the given subject
does not
correspond to a known SQLAlchemy inspected type,
:class:sqlalchemy.exc.NoInspectionAvailable
is raised. If False
, None
is returned.