class ShardedSession(Session):
Undocumented
Method | __init__ |
Construct a ShardedSession. |
Method | connection_callable |
Provide a _engine.Connection to use in the unit of work flush process. |
Method | get_bind |
Return a "bind" to which this .Session is bound. |
Method | _choose_shard_and_assign |
Undocumented |
Method | _identity_lookup |
override the default .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). |
Method | bind_shard |
Undocumented |
Instance Variable | __binds |
Undocumented |
Instance Variable | execute_chooser |
Undocumented |
Instance Variable | id_chooser |
Undocumented |
Instance Variable | query_chooser |
Undocumented |
Instance Variable | shard_chooser |
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_bind |
Undocumented |
Method | _after_attach |
Undocumented |
Method | _autobegin |
Undocumented |
Method | _autoflush |
Undocumented |
Method | _before_attach |
Undocumented |
Method | _bulk_save_mappings |
Undocumented |
Method | _close_impl |
Undocumented |
Method | _conditional_expire |
Expire a state if persistent, else expunge if pending |
Method | _connection_for_bind |
Undocumented |
Method | _contains_state |
Undocumented |
Method | _delete_impl |
Undocumented |
Method | _expire_state |
Undocumented |
Method | _expunge_states |
Undocumented |
Method | _flush |
Undocumented |
Method | _flush_warning |
Undocumented |
Method | _get_impl |
Undocumented |
Method | _is_clean |
Undocumented |
Method | _legacy_transaction |
Undocumented |
Method | _maker_context_manager |
Undocumented |
Method | _merge |
Undocumented |
Method | _register_altered |
Undocumented |
Method | _register_persistent |
Register all persistent objects from a flush. |
Method | _remove_newly_deleted |
Undocumented |
Method | _save_impl |
Undocumented |
Method | _save_or_update_impl |
Undocumented |
Method | _save_or_update_state |
Undocumented |
Method | _update_impl |
Undocumented |
Method | _validate_persistent |
Undocumented |
Method | add |
Place an object in the Session. |
Method | add_all |
Add the given collection of instances to this Session. |
Method | begin |
Begin a transaction, or nested transaction, on this .Session , if one is not already begun. |
Method | begin_nested |
Begin a "nested" transaction on this Session, e.g. SAVEPOINT. |
Method | bind_mapper |
Associate a _orm.Mapper or arbitrary Python class with a "bind", e.g. an _engine.Engine or _engine.Connection . |
Method | bind_table |
Associate a _schema.Table with a "bind", e.g. an _engine.Engine or _engine.Connection . |
Method | bulk_insert_mappings |
Perform a bulk insert of the given list of mapping dictionaries. |
Method | bulk_save_objects |
Perform a bulk save of the given list of objects. |
Method | bulk_update_mappings |
Perform a bulk update of the given list of mapping dictionaries. |
Method | close |
Close out the transactional resources and ORM objects used by this _orm.Session . |
Method | commit |
Flush pending changes and commit the current transaction. |
Method | connection |
Return a _engine.Connection object corresponding to this .Session object's transactional state. |
Method | delete |
Mark an instance as deleted. |
Method | enable_relationship_loading |
Associate an object with this .Session for related object loading. |
Method | execute |
Execute a SQL expression construct. |
Method | expire |
Expire the attributes on an instance. |
Method | expire_all |
Expires all persistent instances within this Session. |
Method | expunge |
Remove the instance from this Session. |
Method | expunge_all |
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_nested_transaction |
Return the current nested transaction in progress, if any. |
Method | get_transaction |
Return the current root transaction in progress, if any. |
Method | in_nested_transaction |
Return True if this _orm.Session has begun a nested transaction, e.g. SAVEPOINT. |
Method | in_transaction |
Return True if this _orm.Session has begun a transaction. |
Method | invalidate |
Close this Session, using connection invalidation. |
Method | is_modified |
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 .Session . |
Method | prepare |
Prepare the current transaction in progress for two phase commit. |
Method | query |
Return a new _query.Query object corresponding to this _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 | _is_asyncio |
Undocumented |
Class Variable | _trans_context_manager |
Undocumented |
Instance Variable | _deleted |
Undocumented |
Instance Variable | _flushing |
Undocumented |
Instance Variable | _nested_transaction |
Undocumented |
Instance Variable | _new |
Undocumented |
Instance Variable | _query_cls |
Undocumented |
Instance Variable | _transaction |
Undocumented |
Instance Variable | _warn_on_events |
Undocumented |
Instance Variable | autocommit |
Undocumented |
Instance Variable | autoflush |
Undocumented |
Instance Variable | bind |
Undocumented |
Instance Variable | enable_baked_queries |
Undocumented |
Instance Variable | expire_on_commit |
Undocumented |
Instance Variable | future |
Undocumented |
Instance Variable | hash_key |
Undocumented |
Instance Variable | identity_map |
A mapping of object identities to objects themselves. |
Instance Variable | twophase |
Undocumented |
Property | _dirty_states |
The set of all persistent states considered dirty. |
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_active |
True if this .Session not in "partial rollback" state. |
Property | new |
The set of all instances marked as 'new' within this Session. |
Property | no_autoflush |
Return a context manager that disables autoflush. |
Property | transaction |
The current active or inactive .SessionTransaction . |
Inherited from _SessionClassMethods
(via Session
):
Class Method | close_all |
Close all sessions in memory. |
Class Method | identity_key |
Return an identity key. |
Class Method | object_session |
Return the .Session to which an object belongs. |
sqlalchemy.orm.session.Session.__init__
Parameters | |
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. |
id_chooser | A callable, passed a query and a tuple of identity values, which should return a list of shard ids where the ID might reside. The databases will be queried in the order of this listing. |
execute_chooser | For a given
Changed in version 1.4: The execute_chooser parameter
supersedes the query_chooser parameter.
|
shards | A dictionary of string shard names
to ~sqlalchemy.engine.Engine objects. |
query_cls | Undocumented |
**kwargs | Undocumented |
_engine.Connection
to use in the unit of work
flush process.sqlalchemy.orm.session.Session.get_bind
Return a "bind" to which this .Session
is bound.
The "bind" is usually an instance of _engine.Engine
,
except in the case where the .Session
has been
explicitly bound directly to a _engine.Connection
.
For a multiply-bound or unbound .Session
, the
mapper or clause arguments are used to determine the
appropriate bind to return.
Note that the "mapper" argument is usually present
when .Session.get_bind
is called via an ORM
operation such as a .Session.query
, each
individual INSERT/UPDATE/DELETE operation within a
.Session.flush
, call, etc.
The order of resolution is:
_schema.Table
objects
found in the given clause present in Session.binds._schema.MetaData
ultimately
associated with the clause._schema.MetaData
ultimately
associated with the _schema.Table
or other
selectable to which the mapper is mapped.~sqlalchemy.exc.UnboundExecutionError
is raised.Note that the .Session.get_bind
method can be overridden on
a user-defined subclass of .Session
to provide any kind
of bind resolution scheme. See the example at
:ref:`session_custom_partitioning`.
See Also
.Session.bind_mapper
.Session.bind_table
Parameters | |
mapper | Optional .mapper mapped class or instance of
_orm.Mapper . The bind can be derived from a
_orm.Mapper
first by consulting the "binds" map associated with this
.Session , and secondly by consulting the
_schema.MetaData
associated with the _schema.Table to which the
_orm.Mapper
is mapped for a bind. |
shard_id | Undocumented |
instance | Undocumented |
clause | A _expression.ClauseElement (i.e.
_expression.select ,
_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 _schema.Table
associated with
bound _schema.MetaData . |
**kw | Undocumented |
override the default .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).
.Session._identity_lookup
from
the _query.Query
object to the .Session
.