common¶
- class advanced_alchemy.config.common.GenericSQLAlchemyConfig[source]¶
Bases:
Generic
[EngineT
,SessionT
,SessionMakerT
]Common SQLAlchemy Configuration.
- create_engine_callable: Callable[[str], EngineT]¶
Callable that creates an
AsyncEngine
instance or instance of its subclass.
- session_config: GenericSessionConfig[Any, Any, Any]¶
Configuration options for either the
async_sessionmaker
orsessionmaker
.
- session_maker_class: type[sessionmaker[Session] | async_sessionmaker[AsyncSession]]¶
Sessionmaker class to use.
- connection_string: str | None = None¶
Database connection string in one of the formats supported by SQLAlchemy.
Notes
For async connections, the connection string must include the correct async prefix. e.g.
'postgresql+asyncpg://...'
instead of'postgresql://'
, and for sync connections its the opposite.
- engine_config: EngineConfig¶
Configuration for the SQLAlchemy engine.
The configuration options are documented in the SQLAlchemy documentation.
- session_maker: Callable[[], SessionT] | None = None¶
Callable that returns a session.
If provided, the plugin will use this rather than instantiate a sessionmaker.
- __init__(create_engine_callable: Callable[[str], EngineT], session_config: GenericSessionConfig[Any, Any, Any], session_maker_class: type[sessionmaker[Session] | async_sessionmaker[AsyncSession]], connection_string: str | None = None, engine_config: EngineConfig = <factory>, session_maker: Callable[[], SessionT] | None = None, engine_instance: EngineT | None = None, create_all: bool = False, metadata: MetaData | None = None, enable_touch_updated_timestamp_listener: bool = True) None ¶
- engine_instance: EngineT | None = None¶
Optional engine to use.
If set, the plugin will use the provided instance rather than instantiate an engine.
- metadata: MetaData | None = None¶
Optional metadata to use.
If set, the plugin will use the provided instance rather than the default metadata.
- enable_touch_updated_timestamp_listener: bool = True¶
Enable Created/Updated Timestamp event listener.
This is a listener that will update
created_at
andupdated_at
columns on record modification. Disable if you plan to bring your own update mechanism for these columns
- property engine_config_dict: dict[str, Any]¶
Return the engine configuration as a dict.
- Returns:
A string keyed dict of config kwargs for the SQLAlchemy
get_engine
function.
- property session_config_dict: dict[str, Any]¶
Return the session configuration as a dict.
- Returns:
A string keyed dict of config kwargs for the SQLAlchemy
sessionmaker
class.
- class advanced_alchemy.config.common.GenericSessionConfig[source]¶
Bases:
Generic
[ConnectionT
,EngineT
,SessionT
]SQLAlchemy async session config.
- autobegin¶
Automatically start transactions when database access is requested by an operation.
alias of
Empty
- autoflush¶
When
True
, all query operations will issue a flush call to thisSession
before proceedingalias of
Empty
- bind¶
The
Engine
orConnection
that newSession
objects will be bound to.alias of
Empty
- binds¶
A dictionary which may specify any number of
Engine
orConnection
objects as the source of connectivity for SQL operations on a per-entity basis. The keys of the dictionary consist of any series of mapped classes, arbitrary Python classes that are bases for mapped classes,Table
objects andMapper
objects. The values of the dictionary are then instances ofEngine
or less commonlyConnection
objects.alias of
Empty
- info¶
Optional dictionary of information that will be available via the
Session.info
alias of
Empty
- join_transaction_mode¶
Describes the transactional behavior to take when a given bind is a Connection that has already begun a transaction outside the scope of this Session; in other words the
Connection.in_transaction()
method returns True.alias of
Empty
- query_cls¶
Class which should be used to create new Query objects, as returned by the
Session.query()
method.alias of
Empty
- twophase¶
When
True
, all transactions will be started as a “two phase” transaction, i.e. using the “two phase” semantics of the database in use along with an XID. During acommit()
, afterflush()
has been issued for all attached databases, theTwoPhaseTransaction.prepare()
method on each database`sTwoPhaseTransaction
will be called. This allows each database to roll back the entire transaction, before each transaction is committed.alias of
Empty
- __init__(autobegin: bool | EmptyType = <class 'advanced_alchemy.utils.dataclass.Empty'>, autoflush: bool | EmptyType = <class 'advanced_alchemy.utils.dataclass.Empty'>, bind: EngineT | ConnectionT | None | EmptyType = <class 'advanced_alchemy.utils.dataclass.Empty'>, binds: dict[type[Any] | Mapper | TableClause | str, EngineT | ConnectionT] | None | EmptyType = <class 'advanced_alchemy.utils.dataclass.Empty'>, class_: type[SessionT] | EmptyType = <class 'advanced_alchemy.utils.dataclass.Empty'>, expire_on_commit: bool | EmptyType = <class 'advanced_alchemy.utils.dataclass.Empty'>, info: dict[str, Any] | None | EmptyType = <class 'advanced_alchemy.utils.dataclass.Empty'>, join_transaction_mode: JoinTransactionMode | EmptyType = <class 'advanced_alchemy.utils.dataclass.Empty'>, query_cls: type[Query] | None | EmptyType = <class 'advanced_alchemy.utils.dataclass.Empty'>, twophase: bool | EmptyType = <class 'advanced_alchemy.utils.dataclass.Empty'>) None ¶
- class advanced_alchemy.config.common.GenericAlembicConfig[source]¶
Bases:
object
Configuration for Alembic’s
Config
.For details see: https://alembic.sqlalchemy.org/en/latest/api/config.html
- __init__(script_config: str = 'alembic.ini', version_table_name: str = 'alembic_versions', version_table_schema: str | None = None, script_location: str = 'migrations', target_metadata: MetaData = MetaData(), user_module_prefix: str | None = 'sa.', render_as_batch: bool = True, compare_type: bool = False, template_path: str = '/home/runner/work/advanced-alchemy/advanced-alchemy/advanced_alchemy/alembic/templates') None ¶
- script_config: str = 'alembic.ini'¶
A path to the Alembic configuration file such as
alembic.ini
. If left unset, the default configuration will be used.
- version_table_name: str = 'alembic_versions'¶
Configure the name of the table used to hold the applied alembic revisions. Defaults to
alembic_versions
.
- version_table_schema: str | None = None¶
Configure the schema to use for the alembic revisions revisions. If unset, it defaults to connection’s default schema.
- target_metadata: MetaData = MetaData()¶
Metadata to use.