Routing
plateforme.core.database.routing
This module defines the DatabaseRouter
abstract class for controlling
database operations in a multi-database environment scenario within the
Plateforme framework.
It provides methods to determine the appropriate database for read and write operations, and to assess if a migration operation should be executed on a specific database.
DatabaseRouter
Bases: ABC
Database engine router for controlling database operations.
A database engine router abstract class to control database operations on models within a multi-database setup.
Note
This class should be used as an interface for database engine routing operations within the Plateforme framework.
get_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. |
None
|
kwargs
|
Any
|
Additional information to assist in selecting an engine. |
{}
|
Returns:
Type | Description |
---|---|
str | None
|
An engine alias if a suggestion is made, else |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/routing.py
get_read_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
|
kwargs
|
Any
|
Additional information to assist in selecting an engine. |
{}
|
Returns:
Type | Description |
---|---|
str | None
|
An engine alias if a suggestion is made, else |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/routing.py
get_write_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
|
kwargs
|
Any
|
Additional information to assist in selecting an engine. |
{}
|
Returns:
Type | Description |
---|---|
str | None
|
An engine alias if a suggestion is made, else |
Source code in .venv/lib/python3.12/site-packages/plateforme/core/database/routing.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 | None
|
|
bool | None
|
opinion. |