Undocumented
Method | __init__ |
Construct a ShardedSession. |
Method | bind |
Undocumented |
Method | connection |
Provide a :class:`_engine.Connection` to use in the unit of work flush process. |
Method | get |
Return a "bind" to which this :class:`.Session` is bound. |
Instance Variable | execute |
Undocumented |
Instance Variable | identity |
Undocumented |
Instance Variable | shard |
Undocumented |
Method | _choose |
Undocumented |
Method | _identity |
override the default :meth:`.Session._identity_lookup` method so that we search for a given non-token primary key identity across all possible identity tokens (e.g. shard ids). |
Instance Variable | __shards |
Undocumented |
Inherited from Session
:
Method | __contains__ |
Return True if the instance is associated with this session. |
Method | __enter__ |
Undocumented |
Method | __exit__ |
Undocumented |
Method | __iter__ |
Iterate over all pending or persistent instances within this Session. |
Method | add |
Place an object into this :class:`_orm.Session`. |
Method | add |
Add the given collection of instances to this :class:`_orm.Session`. |
Method | begin |
Begin a transaction, or nested transaction, on this :class:`.Session`, if one is not already begun. |
Method | begin |
Begin a "nested" transaction on this Session, e.g. SAVEPOINT. |
Method | bind |
Associate a :class:`_orm.Mapper` or arbitrary Python class with a "bind", e.g. an :class:`_engine.Engine` or :class:`_engine.Connection`. |
Method | bind |
Associate a :class:`_schema.Table` with a "bind", e.g. an :class:`_engine.Engine` or :class:`_engine.Connection`. |
Method | bulk |
Perform a bulk insert of the given list of mapping dictionaries. |
Method | bulk |
Perform a bulk save of the given list of objects. |
Method | bulk |
Perform a bulk update of the given list of mapping dictionaries. |
Method | close |
Close out the transactional resources and ORM objects used by this :class:`_orm.Session`. |
Method | commit |
Flush pending changes and commit the current transaction. |
Method | connection |
Return a :class:`_engine.Connection` object corresponding to this :class:`.Session` object's transactional state. |
Method | delete |
Mark an instance as deleted. |
Method | enable |
Associate an object with this :class:`.Session` for related object loading. |
Method | execute |
Execute a SQL expression construct. |
Method | expire |
Expire the attributes on an instance. |
Method | expire |
Expires all persistent instances within this Session. |
Method | expunge |
Remove the `instance` from this ``Session``. |
Method | expunge |
Remove all object instances from this ``Session``. |
Method | flush |
Flush all the object changes to the database. |
Method | get |
Return an instance based on the given primary key identifier, or ``None`` if not found. |
Method | get |
Return the current nested transaction in progress, if any. |
Method | get |
Return the current root transaction in progress, if any. |
Method | in |
Return True if this :class:`_orm.Session` has begun a nested transaction, e.g. SAVEPOINT. |
Method | in |
Return True if this :class:`_orm.Session` has begun a transaction. |
Method | invalidate |
Close this Session, using connection invalidation. |
Method | is |
Return ``True`` if the given instance has locally modified attributes. |
Method | merge |
Copy the state of a given instance into a corresponding instance within this :class:`.Session`. |
Method | prepare |
Prepare the current transaction in progress for two phase commit. |
Method | query |
Return a new :class:`_query.Query` object corresponding to this :class:`_orm.Session`. |
Method | refresh |
Expire and refresh attributes on the given instance. |
Method | rollback |
Rollback the current transaction in progress. |
Method | scalar |
Execute a statement and return a scalar result. |
Method | scalars |
Execute a statement and return the results as scalars. |
Class Variable | dispatch |
Undocumented |
Instance Variable | autobegin |
Undocumented |
Instance Variable | autoflush |
Undocumented |
Instance Variable | bind |
Undocumented |
Instance Variable | enable |
Undocumented |
Instance Variable | expire |
Undocumented |
Instance Variable | hash |
Undocumented |
Instance Variable | identity |
A mapping of object identities to objects themselves. |
Instance Variable | join |
Undocumented |
Instance Variable | twophase |
Undocumented |
Property | deleted |
The set of all instances marked as 'deleted' within this ``Session`` |
Property | dirty |
The set of all persistent instances considered dirty. |
Property | info |
A user-modifiable dictionary. |
Property | is |
True if this :class:`.Session` not in "partial rollback" state. |
Property | new |
The set of all instances marked as 'new' within this ``Session``. |
Property | no |
Return a context manager that disables autoflush. |
Method | _add |
Undocumented |
Method | _after |
Undocumented |
Method | _autobegin |
Undocumented |
Method | _autoflush |
Undocumented |
Method | _before |
Undocumented |
Method | _bulk |
Undocumented |
Method | _close |
Undocumented |
Method | _conditional |
Expire a state if persistent, else expunge if pending |
Method | _connection |
Undocumented |
Method | _contains |
Undocumented |
Method | _delete |
Undocumented |
Method | _execute |
Undocumented |
Method | _expire |
Undocumented |
Method | _expunge |
Undocumented |
Method | _flush |
Undocumented |
Method | _flush |
Undocumented |
Method | _get |
Undocumented |
Method | _is |
Undocumented |
Method | _maker |
Undocumented |
Method | _merge |
Undocumented |
Method | _register |
Undocumented |
Method | _register |
Register all persistent objects from a flush. |
Method | _remove |
Undocumented |
Method | _save |
Undocumented |
Method | _save |
Undocumented |
Method | _save |
Undocumented |
Method | _update |
Undocumented |
Method | _validate |
Undocumented |
Class Variable | _is |
Undocumented |
Class Variable | _trans |
Undocumented |
Instance Variable | __binds |
Undocumented |
Instance Variable | _deleted |
Undocumented |
Instance Variable | _flushing |
Undocumented |
Instance Variable | _nested |
Undocumented |
Instance Variable | _new |
Undocumented |
Instance Variable | _query |
Undocumented |
Instance Variable | _transaction |
Undocumented |
Instance Variable | _warn |
Undocumented |
Property | _dirty |
The set of all persistent states considered dirty. |
Inherited from _SessionClassMethods
(via Session
):
Class Method | close |
Close *all* sessions in memory. |
Class Method | identity |
Return an identity key. |
Class Method | object |
Return the :class:`.Session` to which an object belongs. |
ShardChooser
, identity_chooser: Optional[ IdentityChooser]
= None, execute_chooser: Optional[ Callable[ [ ORMExecuteState], Iterable[ Any]]]
= None, shards: Optional[ Dict[ str, Any]]
= None, query_cls: Type[ Query[ _T]]
= ShardedQuery, *, id_chooser: Optional[ Callable[ [ Query[ _T], Iterable[ _T]], Iterable[ Any]]]
= None, query_chooser: Optional[ Callable[ [ Executable], Iterable[ Any]]]
= None, **kwargs: Any
):
(source)
¶
sqlalchemy.orm.session.Session.__init__
Construct a ShardedSession. :param shard_chooser: A callable which, passed a Mapper, a mapped instance, and possibly a SQL clause, returns a shard ID. This id may be based off of the attributes present within the object, or on some round-robin scheme. If the scheme is based on a selection, it should set whatever state on the instance to mark it in the future as participating in that shard. :param identity_chooser: A callable, passed a Mapper and primary key argument, which should return a list of shard ids where this primary key might reside. .. versionchanged:: 2.0 The ``identity_chooser`` parameter supersedes the ``id_chooser`` parameter. :param execute_chooser: For a given :class:`.ORMExecuteState`, returns the list of shard_ids where the query should be issued. Results from all shards returned will be combined together into a single listing. .. versionchanged:: 1.4 The ``execute_chooser`` parameter supersedes the ``query_chooser`` parameter. :param shards: A dictionary of string shard names to :class:`~sqlalchemy.engine.Engine` objects.
Optional[ Mapper[ _T]]
= None, instance: Optional[ Any]
= None, shard_id: Optional[ ShardIdentifier]
= None, **kw: Any
) -> Connection
:
(source)
¶
Provide a :class:`_engine.Connection` to use in the unit of work flush process.
Optional[ _EntityBindKey[ _O]]
= None, *, shard_id: Optional[ ShardIdentifier]
= None, instance: Optional[ Any]
= None, clause: Optional[ ClauseElement]
= None, **kw: Any
) -> _SessionBind
:
(source)
¶
sqlalchemy.orm.session.Session.get_bind
Return a "bind" to which this :class:`.Session` is bound. The "bind" is usually an instance of :class:`_engine.Engine`, except in the case where the :class:`.Session` has been explicitly bound directly to a :class:`_engine.Connection`. For a multiply-bound or unbound :class:`.Session`, the ``mapper`` or ``clause`` arguments are used to determine the appropriate bind to return. Note that the "mapper" argument is usually present when :meth:`.Session.get_bind` is called via an ORM operation such as a :meth:`.Session.query`, each individual INSERT/UPDATE/DELETE operation within a :meth:`.Session.flush`, call, etc. The order of resolution is: 1. if mapper given and :paramref:`.Session.binds` is present, locate a bind based first on the mapper in use, then on the mapped class in use, then on any base classes that are present in the ``__mro__`` of the mapped class, from more specific superclasses to more general. 2. if clause given and ``Session.binds`` is present, locate a bind based on :class:`_schema.Table` objects found in the given clause present in ``Session.binds``. 3. if ``Session.binds`` is present, return that. 4. if clause given, attempt to return a bind linked to the :class:`_schema.MetaData` ultimately associated with the clause. 5. if mapper given, attempt to return a bind linked to the :class:`_schema.MetaData` ultimately associated with the :class:`_schema.Table` or other selectable to which the mapper is mapped. 6. No bind can be found, :exc:`~sqlalchemy.exc.UnboundExecutionError` is raised. Note that the :meth:`.Session.get_bind` method can be overridden on a user-defined subclass of :class:`.Session` to provide any kind of bind resolution scheme. See the example at :ref:`session_custom_partitioning`. :param mapper: Optional mapped class or corresponding :class:`_orm.Mapper` instance. The bind can be derived from a :class:`_orm.Mapper` first by consulting the "binds" map associated with this :class:`.Session`, and secondly by consulting the :class:`_schema.MetaData` associated with the :class:`_schema.Table` to which the :class:`_orm.Mapper` is mapped for a bind. :param clause: A :class:`_expression.ClauseElement` (i.e. :func:`_expression.select`, :func:`_expression.text`, etc.). If the ``mapper`` argument is not present or could not produce a bind, the given expression construct will be searched for a bound element, typically a :class:`_schema.Table` associated with bound :class:`_schema.MetaData`. .. seealso:: :ref:`session_partitioning` :paramref:`.Session.binds` :meth:`.Session.bind_mapper` :meth:`.Session.bind_table`
Optional[ _EntityBindKey[ _O]]
, instance: Any
, **kw: Any
) -> Any
:
(source)
¶
Undocumented
Mapper[ _O]
, primary_key_identity: Union[ Any, Tuple[ Any, ...]]
, identity_token: Optional[ Any]
= None, passive: PassiveFlag
= PassiveFlag.PASSIVE_OFF, lazy_loaded_from: Optional[ InstanceState[ Any]]
= None, execution_options: OrmExecuteOptionsParameter
= util.EMPTY_DICT, bind_arguments: Optional[ _BindArguments]
= None, **kw: Any
) -> Union[ Optional[ _O], LoaderCallableStatus]
:
(source)
¶
override the default :meth:`.Session._identity_lookup` method so that we search for a given non-token primary key identity across all possible identity tokens (e.g. shard ids). .. versionchanged:: 1.4 Moved :meth:`.Session._identity_lookup` from the :class:`_query.Query` object to the :class:`.Session`.