desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Mark the method as replacing an entity in the collection.
Adds "add to collection" and "remove from collection" handling to
the method. The decorator argument indicates which method argument
holds the SQLAlchemy-relevant value to be added, and return value, if
any will be considered the value to remove.
Arguments can... | @staticmethod
def replaces(arg):
| def decorator(fn):
fn._sa_instrument_before = ('fire_append_event', arg)
fn._sa_instrument_after = 'fire_remove_event'
return fn
return decorator
|
'Mark the method as removing an entity in the collection.
Adds "remove from collection" handling to the method. The decorator
argument indicates which method argument holds the SQLAlchemy-relevant
value to be removed. Arguments can be specified positionally (i.e.
integer) or by name::
@collection.removes(1)
def zap(se... | @staticmethod
def removes(arg):
| def decorator(fn):
fn._sa_instrument_before = ('fire_remove_event', arg)
return fn
return decorator
|
'Mark the method as removing an entity in the collection.
Adds "remove from collection" handling to the method. The return value
of the method, if any, is considered the value to remove. The method
arguments are not inspected::
@collection.removes_return()
def pop(self): ...
For methods where the value to remove is k... | @staticmethod
def removes_return():
| def decorator(fn):
fn._sa_instrument_after = 'fire_remove_event'
return fn
return decorator
|
'The entity collection being adapted.'
| @property
def data(self):
| return self._data()
|
'Link a collection to this adapter'
| def link_to_self(self, data):
| data._sa_adapter = self
if data._sa_linker:
data._sa_linker(self)
|
'Unlink a collection from any adapter'
| def unlink(self, data):
| del data._sa_adapter
if data._sa_linker:
data._sa_linker(None)
|
'Converts collection-compatible objects to an iterable of values.
Can be passed any type of object, and if the underlying collection
determines that it can be adapted into a stream of values it can
use, returns an iterable of values suitable for append()ing.
This method may raise TypeError or any other suitable excepti... | def adapt_like_to_iterable(self, obj):
| converter = self._data()._sa_converter
if (converter is not None):
return converter(obj)
setting_type = util.duck_type_collection(obj)
receiving_type = util.duck_type_collection(self._data())
if ((obj is None) or (setting_type != receiving_type)):
given = (((obj is None) and 'None') ... |
'Add an entity to the collection, firing mutation events.'
| def append_with_event(self, item, initiator=None):
| self._data()._sa_appender(item, _sa_initiator=initiator)
|
'Add or restore an entity to the collection, firing no events.'
| def append_without_event(self, item):
| self._data()._sa_appender(item, _sa_initiator=False)
|
'Add or restore an entity to the collection, firing no events.'
| def append_multiple_without_event(self, items):
| appender = self._data()._sa_appender
for item in items:
appender(item, _sa_initiator=False)
|
'Remove an entity from the collection, firing mutation events.'
| def remove_with_event(self, item, initiator=None):
| self._data()._sa_remover(item, _sa_initiator=initiator)
|
'Remove an entity from the collection, firing no events.'
| def remove_without_event(self, item):
| self._data()._sa_remover(item, _sa_initiator=False)
|
'Empty the collection, firing a mutation event for each entity.'
| def clear_with_event(self, initiator=None):
| remover = self._data()._sa_remover
for item in list(self):
remover(item, _sa_initiator=initiator)
|
'Empty the collection, firing no events.'
| def clear_without_event(self):
| remover = self._data()._sa_remover
for item in list(self):
remover(item, _sa_initiator=False)
|
'Iterate over entities in the collection.'
| def __iter__(self):
| return iter(self._data()._sa_iterator())
|
'Count entities in the collection.'
| def __len__(self):
| return len(list(self._data()._sa_iterator()))
|
'Notify that a entity has entered the collection.
Initiator is a token owned by the InstrumentedAttribute that
initiated the membership mutation, and should be left as None
unless you are passing along an initiator value from a chained
operation.'
| def fire_append_event(self, item, initiator=None):
| if (initiator is not False):
if self.invalidated:
self._warn_invalidated()
return self.attr.fire_append_event(self.owner_state, self.owner_state.dict, item, initiator)
else:
return item
|
'Notify that a entity has been removed from the collection.
Initiator is the InstrumentedAttribute that initiated the membership
mutation, and should be left as None unless you are passing along
an initiator value from a chained operation.'
| def fire_remove_event(self, item, initiator=None):
| if (initiator is not False):
if self.invalidated:
self._warn_invalidated()
self.attr.fire_remove_event(self.owner_state, self.owner_state.dict, item, initiator)
|
'Notify that an entity is about to be removed from the collection.
Only called if the entity cannot be removed after calling
fire_remove_event().'
| def fire_pre_remove_event(self, initiator=None):
| if self.invalidated:
self._warn_invalidated()
self.attr.fire_pre_remove_event(self.owner_state, self.owner_state.dict, initiator=initiator)
|
'Create a new collection with keying provided by keyfunc.
keyfunc may be any callable any callable that takes an object and
returns an object for use as a dictionary key.
The keyfunc will be called every time the ORM needs to add a member by
value-only (such as when loading instances from the database) or
remove a memb... | def __init__(self, keyfunc):
| self.keyfunc = keyfunc
|
'Add an item by value, consulting the keyfunc for the key.'
| @collection.appender
@collection.internally_instrumented
def set(self, value, _sa_initiator=None):
| key = self.keyfunc(value)
self.__setitem__(key, value, _sa_initiator)
|
'Remove an item by value, consulting the keyfunc for the key.'
| @collection.remover
@collection.internally_instrumented
def remove(self, value, _sa_initiator=None):
| key = self.keyfunc(value)
if (self[key] != value):
raise sa_exc.InvalidRequestError(("Can not remove '%s': collection holds '%s' for key '%s'. Possible cause: is the MappedCollection key function based on mutable properties or properties ... |
'Validate and convert a dict-like object into values for set()ing.
This is called behind the scenes when a MappedCollection is replaced
entirely by another collection, as in::
myobj.mappedcollection = {\'a\':obj1, \'b\': obj2} # ...
Raises a TypeError if the key in any (key, value) pair in the dictlike
object does not ... | @collection.converter
def _convert(self, dictlike):
| for (incoming_key, value) in util.dictlike_iteritems(dictlike):
new_key = self.keyfunc(value)
if (incoming_key != new_key):
raise TypeError(("Found incompatible key %r for value %r; this collection's keying function requires a key of %r for... |
'return an iterator of all classbound attributes that are
implement :class:`._InspectionAttr`.
This includes :class:`.QueryableAttribute` as well as extension
types such as :class:`.hybrid_property` and :class:`.AssociationProxy`.'
| def _all_sqla_attributes(self, exclude=None):
| if (exclude is None):
exclude = set()
for supercls in self.class_.__mro__:
for key in set(supercls.__dict__).difference(exclude):
exclude.add(key)
val = supercls.__dict__[key]
if isinstance(val, interfaces._InspectionAttr):
(yield (key, val))
|
'Return True if the given attribute is fully initialized.
i.e. has an impl.'
| def _attr_has_impl(self, key):
| return ((key in self) and (self[key].impl is not None))
|
'Create a new ClassManager for a subclass of this ClassManager\'s
class.
This is called automatically when attributes are instrumented so that
the attributes can be propagated to subclasses against their own
class-local manager, without the need for mappers etc. to have already
pre-configured managers for the full clas... | def _subclass_manager(self, cls):
| manager = manager_of_class(cls)
if (manager is None):
manager = _instrumentation_factory.create_manager_for_cls(cls)
return manager
|
'Mark this instance as the manager for its class.'
| def manage(self):
| setattr(self.class_, self.MANAGER_ATTR, self)
|
'Dissasociate this manager from its class.'
| def dispose(self):
| delattr(self.class_, self.MANAGER_ATTR)
|
'Return a (instance) -> InstanceState callable.
"state getter" callables should raise either KeyError or
AttributeError if no InstanceState could be found for the
instance.'
| @util.hybridmethod
def state_getter(self):
| return _default_state_getter
|
'remove all instrumentation established by this ClassManager.'
| def unregister(self):
| self._uninstrument_init()
self.mapper = self.dispatch = None
self.info.clear()
for key in list(self):
if (key in self.local_attrs):
self.uninstrument_attribute(key)
|
'Install a default InstanceState if none is present.
A private convenience method used by the __init__ decorator.'
| def _new_state_if_none(self, instance):
| if hasattr(instance, self.STATE_ATTR):
return False
elif ((self.class_ is not instance.__class__) and self.is_mapped):
return self._subclass_manager(instance.__class__)._new_state_if_none(instance)
else:
state = self._state_constructor(instance, self)
setattr(instance, self.S... |
'TODO'
| def has_parent(self, state, key, optimistic=False):
| return self.get_impl(key).hasparent(state, optimistic=optimistic)
|
'All ClassManagers are non-zero regardless of attribute state.'
| def __bool__(self):
| return True
|
'Overridden by a subclass to do an extended lookup.'
| def _locate_extended_factory(self, class_):
| return (None, None)
|
'Overridden by a subclass to test for conflicting factories.'
| def _check_conflicts(self, class_, factory):
| return
|
'Return the \'info\' dictionary for the underlying SQL element.
The behavior here is as follows:
* If the attribute is a column-mapped property, i.e.
:class:`.ColumnProperty`, which is mapped directly
to a schema-level :class:`.Column` object, this attribute
will return the :attr:`.SchemaItem.info` dictionary associate... | @util.memoized_property
def info(self):
| return self.comparator.info
|
'Return an inspection instance representing the parent.
This will be either an instance of :class:`.Mapper`
or :class:`.AliasedInsp`, depending upon the nature
of the parent entity which this attribute is associated
with.'
| @util.memoized_property
def parent(self):
| return inspection.inspect(self._parententity)
|
'like __clause_element__(), but called specifically
by :class:`.Query` to allow special behavior.'
| def _query_clause_element(self):
| return self.comparator._query_clause_element()
|
'Return the :class:`.MapperProperty` associated with this
:class:`.QueryableAttribute`.
Return values here will commonly be instances of
:class:`.ColumnProperty` or :class:`.RelationshipProperty`.'
| @util.memoized_property
def property(self):
| return self.comparator.property
|
'Construct an AttributeImpl.
\class_
associated class
key
string name of the attribute
\callable_
optional function which generates a callable based on a parent
instance, which produces the "default" values for a scalar or
collection attribute when it\'s first accessed, if not present
already.
trackparent
if True, atte... | def __init__(self, class_, key, callable_, dispatch, trackparent=False, extension=None, compare_function=None, active_history=False, parent_token=None, expire_missing=True, send_modified_events=True, **kwargs):
| self.class_ = class_
self.key = key
self.callable_ = callable_
self.dispatch = dispatch
self.trackparent = trackparent
self.parent_token = (parent_token or self)
self.send_modified_events = send_modified_events
if (compare_function is None):
self.is_equal = operator.eq
else:
... |
'Backwards compat for impl.active_history'
| def _get_active_history(self):
| return self.dispatch._active_history
|
'Return the boolean value of a `hasparent` flag attached to
the given state.
The `optimistic` flag determines what the default return value
should be if no `hasparent` flag can be located.
As this function is used to determine if an instance is an
*orphan*, instances that were loaded from storage should be
assumed to n... | def hasparent(self, state, optimistic=False):
| msg = 'This AttributeImpl is not configured to track parents.'
assert self.trackparent, msg
return (state.parents.get(id(self.parent_token), optimistic) is not False)
|
'Set a boolean flag on the given item corresponding to
whether or not it is attached to a parent object via the
attribute represented by this ``InstrumentedAttribute``.'
| def sethasparent(self, state, parent_state, value):
| msg = 'This AttributeImpl is not configured to track parents.'
assert self.trackparent, msg
id_ = id(self.parent_token)
if value:
state.parents[id_] = parent_state
else:
if (id_ in state.parents):
last_parent = state.parents[id_]
if ((last... |
'Set a callable function for this attribute on the given object.
This callable will be executed when the attribute is next
accessed, and is assumed to construct part of the instances
previously stored state. When its value or values are loaded,
they will be established as part of the instance\'s *committed
state*. Whi... | def set_callable(self, state, callable_):
| state.callables[self.key] = callable_
|
'Return a list of tuples of (state, obj)
for all objects in this attribute\'s current state
+ history.
Only applies to object-based attributes.
This is an inlining of existing functionality
which roughly corresponds to:
get_state_history(
state,
key,
passive=PASSIVE_NO_INITIALIZE).sum()'
| def get_all_pending(self, state, dict_):
| raise NotImplementedError()
|
'Initialize the given state\'s attribute with an empty value.'
| def initialize(self, state, dict_):
| dict_[self.key] = None
return None
|
'Retrieve a value from the given object.
If a callable is assembled on this object\'s attribute, and
passive is False, the callable will be executed and the
resulting value will be set as the new value for this attribute.'
| def get(self, state, dict_, passive=PASSIVE_OFF):
| if (self.key in dict_):
return dict_[self.key]
else:
key = self.key
if ((key not in state.committed_state) or (state.committed_state[key] is NEVER_SET)):
if (not (passive & CALLABLES_OK)):
return PASSIVE_NO_RESULT
if (key in state.callables):
... |
'return the unchanged value of this attribute'
| def get_committed_value(self, state, dict_, passive=PASSIVE_OFF):
| if (self.key in state.committed_state):
value = state.committed_state[self.key]
if (value is NO_VALUE):
return None
else:
return value
else:
return self.get(state, dict_, passive=passive)
|
'set an attribute value on the given instance and \'commit\' it.'
| def set_committed_value(self, state, dict_, value):
| dict_[self.key] = value
state._commit(dict_, [self.key])
return value
|
'Set a value on the given InstanceState.'
| def set(self, state, dict_, value, initiator, passive=PASSIVE_OFF, check_old=None, pop=False):
| if self.dispatch._active_history:
old = self.get(state, dict_, passive=(PASSIVE_ONLY_PERSISTENT | NO_AUTOFLUSH))
else:
old = self.get(state, dict_, passive=PASSIVE_NO_FETCH)
if ((check_old is not None) and (old is not PASSIVE_NO_RESULT) and (check_old is not old)):
if pop:
... |
'Initialize this attribute with an empty collection.'
| def initialize(self, state, dict_):
| (_, user_data) = self._initialize_collection(state)
dict_[self.key] = user_data
return user_data
|
'Set a value on the given object.'
| def set(self, state, dict_, value, initiator, passive=PASSIVE_OFF, pop=False):
| self._set_iterable(state, dict_, value, (lambda adapter, i: adapter.adapt_like_to_iterable(i)))
|
'Set a collection value from an iterable of state-bearers.
``adapter`` is an optional callable invoked with a CollectionAdapter
and the iterable. Should return an iterable of state-bearing
instances suitable for appending via a CollectionAdapter. Can be used
for, e.g., adapting an incoming dictionary into an iterator... | def _set_iterable(self, state, dict_, iterable, adapter=None):
| (new_collection, user_data) = self._initialize_collection(state)
if adapter:
new_values = list(adapter(new_collection, iterable))
else:
new_values = list(iterable)
old = self.get(state, dict_, passive=PASSIVE_ONLY_PERSISTENT)
if (old is PASSIVE_NO_RESULT):
old = self.initiali... |
'Set an attribute value on the given instance and \'commit\' it.'
| def set_committed_value(self, state, dict_, value):
| (collection, user_data) = self._initialize_collection(state)
if value:
collection.append_multiple_without_event(value)
state.dict[self.key] = user_data
state._commit(dict_, [self.key])
if (self.key in state._pending_mutations):
state._modified_event(dict_, self, user_data, True)
... |
'Retrieve the CollectionAdapter associated with the given state.
Creates a new CollectionAdapter if one does not exist.'
| def get_collection(self, state, dict_, user_data=None, passive=PASSIVE_OFF):
| if (user_data is None):
user_data = self.get(state, dict_, passive=passive)
if (user_data is PASSIVE_NO_RESULT):
return user_data
return getattr(user_data, '_sa_adapter')
|
'Return True if this :class:`.History` has no changes
and no existing, unchanged state.'
| def empty(self):
| return (not bool(((self.added or self.deleted) or (self.unchanged and (self.unchanged != [None])))))
|
'Return a collection of added + unchanged + deleted.'
| def sum(self):
| return (((self.added or []) + (self.unchanged or [])) + (self.deleted or []))
|
'Return a collection of added + unchanged.'
| def non_deleted(self):
| return ((self.added or []) + (self.unchanged or []))
|
'Return a collection of unchanged + deleted.'
| def non_added(self):
| return ((self.unchanged or []) + (self.deleted or []))
|
'Return True if this :class:`.History` has changes.'
| def has_changes(self):
| return bool((self.added or self.deleted))
|
'Adapt a :class:`.PoolListener` to individual
:class:`event.Dispatch` events.'
| @classmethod
def _adapt_listener(cls, self, listener):
| listener = util.as_interface(listener, methods=('connect', 'first_connect', 'checkout', 'checkin'))
if hasattr(listener, 'connect'):
event.listen(self, 'connect', listener.connect)
if hasattr(listener, 'first_connect'):
event.listen(self, 'first_connect', listener.first_connect)
if hasat... |
'Intercept high level execute() events.'
| def execute(self, conn, execute, clauseelement, *multiparams, **params):
| return execute(clauseelement, *multiparams, **params)
|
'Intercept low-level cursor execute() events.'
| def cursor_execute(self, execute, cursor, statement, parameters, context, executemany):
| return execute(cursor, statement, parameters, context)
|
'Intercept begin() events.'
| def begin(self, conn, begin):
| return begin()
|
'Intercept rollback() events.'
| def rollback(self, conn, rollback):
| return rollback()
|
'Intercept commit() events.'
| def commit(self, conn, commit):
| return commit()
|
'Intercept savepoint() events.'
| def savepoint(self, conn, savepoint, name=None):
| return savepoint(name=name)
|
'Intercept rollback_savepoint() events.'
| def rollback_savepoint(self, conn, rollback_savepoint, name, context):
| return rollback_savepoint(name, context)
|
'Intercept release_savepoint() events.'
| def release_savepoint(self, conn, release_savepoint, name, context):
| return release_savepoint(name, context)
|
'Intercept begin_twophase() events.'
| def begin_twophase(self, conn, begin_twophase, xid):
| return begin_twophase(xid)
|
'Intercept prepare_twophase() events.'
| def prepare_twophase(self, conn, prepare_twophase, xid):
| return prepare_twophase(xid)
|
'Intercept rollback_twophase() events.'
| def rollback_twophase(self, conn, rollback_twophase, xid, is_prepared):
| return rollback_twophase(xid, is_prepared)
|
'Intercept commit_twophase() events.'
| def commit_twophase(self, conn, commit_twophase, xid, is_prepared):
| return commit_twophase(xid, is_prepared)
|
'Construct a new :class:`.AssociationProxy`.
The :func:`.association_proxy` function is provided as the usual
entrypoint here, though :class:`.AssociationProxy` can be instantiated
and/or subclassed directly.
:param target_collection: Name of the collection we\'ll proxy to,
usually created with :func:`.relationship`.
:... | def __init__(self, target_collection, attr, creator=None, getset_factory=None, proxy_factory=None, proxy_bulk_set=None):
| self.target_collection = target_collection
self.value_attr = attr
self.creator = creator
self.getset_factory = getset_factory
self.proxy_factory = proxy_factory
self.proxy_bulk_set = proxy_bulk_set
self.owning_class = None
self.key = ('_%s_%s_%s' % (type(self).__name__, target_collection... |
'The \'remote\' :class:`.MapperProperty` referenced by this
:class:`.AssociationProxy`.
.. versionadded:: 0.7.3
See also:
:attr:`.AssociationProxy.attr`
:attr:`.AssociationProxy.local_attr`'
| @property
def remote_attr(self):
| return getattr(self.target_class, self.value_attr)
|
'The \'local\' :class:`.MapperProperty` referenced by this
:class:`.AssociationProxy`.
.. versionadded:: 0.7.3
See also:
:attr:`.AssociationProxy.attr`
:attr:`.AssociationProxy.remote_attr`'
| @property
def local_attr(self):
| return getattr(self.owning_class, self.target_collection)
|
'Return a tuple of ``(local_attr, remote_attr)``.
This attribute is convenient when specifying a join
using :meth:`.Query.join` across two relationships::
sess.query(Parent).join(*Parent.proxied.attr)
.. versionadded:: 0.7.3
See also:
:attr:`.AssociationProxy.local_attr`
:attr:`.AssociationProxy.remote_attr`'
| @property
def attr(self):
| return (self.local_attr, self.remote_attr)
|
'The intermediary class handled by this :class:`.AssociationProxy`.
Intercepted append/set/assignment events will result
in the generation of new instances of this class.'
| @util.memoized_property
def target_class(self):
| return self._get_property().mapper.class_
|
'Return ``True`` if this :class:`.AssociationProxy` proxies a scalar
relationship on the local side.'
| @util.memoized_property
def scalar(self):
| scalar = (not self._get_property().uselist)
if scalar:
self._initialize_scalar_accessors()
return scalar
|
'Produce a proxied \'any\' expression using EXISTS.
This expression will be a composed product
using the :meth:`.RelationshipProperty.Comparator.any`
and/or :meth:`.RelationshipProperty.Comparator.has`
operators of the underlying proxied attributes.'
| def any(self, criterion=None, **kwargs):
| if self._value_is_scalar:
value_expr = getattr(self.target_class, self.value_attr).has(criterion, **kwargs)
else:
value_expr = getattr(self.target_class, self.value_attr).any(criterion, **kwargs)
if (self.scalar and (not self._value_is_scalar)):
return self._comparator.has(value_expr... |
'Produce a proxied \'has\' expression using EXISTS.
This expression will be a composed product
using the :meth:`.RelationshipProperty.Comparator.any`
and/or :meth:`.RelationshipProperty.Comparator.has`
operators of the underlying proxied attributes.'
| def has(self, criterion=None, **kwargs):
| if self._target_is_object:
return self._comparator.has(getattr(self.target_class, self.value_attr).has(criterion, **kwargs))
else:
if ((criterion is not None) or kwargs):
raise exc.ArgumentError('Non-empty has() not allowed for column-targeted association proxy; ... |
'Produce a proxied \'contains\' expression using EXISTS.
This expression will be a composed product
using the :meth:`.RelationshipProperty.Comparator.any`
, :meth:`.RelationshipProperty.Comparator.has`,
and/or :meth:`.RelationshipProperty.Comparator.contains`
operators of the underlying proxied attributes.'
| def contains(self, obj):
| if (self.scalar and (not self._value_is_scalar)):
return self._comparator.has(getattr(self.target_class, self.value_attr).contains(obj))
else:
return self._comparator.any(**{self.value_attr: obj})
|
'Constructs an _AssociationCollection.
This will always be a subclass of either _AssociationList,
_AssociationSet, or _AssociationDict.
lazy_collection
A callable returning a list-based collection of entities (usually an
object attribute managed by a SQLAlchemy relationship())
creator
A function that creates new target... | def __init__(self, lazy_collection, creator, getter, setter, parent):
| self.lazy_collection = lazy_collection
self.creator = creator
self.getter = getter
self.setter = setter
self.parent = parent
|
'Iterate over proxied values.
For the actual domain objects, iterate over .col instead or
just use the underlying collection directly from its property
on the parent.'
| def __iter__(self):
| for member in self.col:
(yield self._get(member))
raise StopIteration
|
'Not supported, use reversed(mylist)'
| def reverse(self):
| raise NotImplementedError
|
'Not supported, use sorted(mylist)'
| def sort(self):
| raise NotImplementedError
|
'Iterate over proxied values.
For the actual domain objects, iterate over .col instead or just use
the underlying collection directly from its property on the parent.'
| def __iter__(self):
| for member in self.col:
(yield self._get(member))
raise StopIteration
|
'Create a new :class:`.hybrid_method`.
Usage is typically via decorator::
from sqlalchemy.ext.hybrid import hybrid_method
class SomeClass(object):
@hybrid_method
def value(self, x, y):
return self._value + x + y
@value.expression
def value(self, x, y):
return func.some_function(self._value, x, y)'
| def __init__(self, func, expr=None):
| self.func = func
self.expr = (expr or func)
|
'Provide a modifying decorator that defines a
SQL-expression producing method.'
| def expression(self, expr):
| self.expr = expr
return self
|
'Create a new :class:`.hybrid_property`.
Usage is typically via decorator::
from sqlalchemy.ext.hybrid import hybrid_property
class SomeClass(object):
@hybrid_property
def value(self):
return self._value
@value.setter
def value(self, value):
self._value = value'
| def __init__(self, fget, fset=None, fdel=None, expr=None):
| self.fget = fget
self.fset = fset
self.fdel = fdel
self.expr = (expr or fget)
util.update_wrapper(self, fget)
|
'Provide a modifying decorator that defines a value-setter method.'
| def setter(self, fset):
| self.fset = fset
return self
|
'Provide a modifying decorator that defines a
value-deletion method.'
| def deleter(self, fdel):
| self.fdel = fdel
return self
|
'Provide a modifying decorator that defines a SQL-expression
producing method.'
| def expression(self, expr):
| self.expr = expr
return self
|
'Provide a modifying decorator that defines a custom
comparator producing method.
The return value of the decorated method should be an instance of
:class:`~.hybrid.Comparator`.'
| def comparator(self, comparator):
| proxy_attr = attributes.create_proxied_attribute(self)
def expr(owner):
return proxy_attr(owner, self.__name__, self, comparator(owner))
self.expr = expr
return self
|
'Reflect all :class:`.Table` objects for all current
:class:`.DeferredReflection` subclasses'
| @classmethod
def prepare(cls, engine):
| to_map = _DeferredMapperConfig.classes_for_base(cls)
for thingy in to_map:
cls._sa_decl_prepare(thingy.local_table, engine)
thingy.map()
mapper = thingy.cls.__mapper__
metadata = mapper.class_.metadata
for rel in mapper._props.values():
if (isinstance(rel, pro... |
'return a new query, limited to a single shard ID.
all subsequent operations with the returned query will
be against the single shard regardless of other state.'
| def set_shard(self, shard_id):
| q = self._clone()
q._shard_id = shard_id
return q
|
'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 stat... | def __init__(self, shard_chooser, id_chooser, query_chooser, shards=None, query_cls=ShardedQuery, **kwargs):
| super(ShardedSession, self).__init__(query_cls=query_cls, **kwargs)
self.shard_chooser = shard_chooser
self.id_chooser = id_chooser
self.query_chooser = query_chooser
self.__binds = {}
self.connection_callable = self.connection
if (shards is not None):
for k in shards:
se... |
'A custom list that manages position information for its children.
``OrderingList`` is a ``collection_class`` list implementation that
syncs position in a Python list with a position attribute on the
mapped objects.
This implementation relies on the list starting in the proper order,
so be **sure** to put an ``order_by... | def __init__(self, ordering_attr=None, ordering_func=None, reorder_on_append=False):
| self.ordering_attr = ordering_attr
if (ordering_func is None):
ordering_func = count_from_0
self.ordering_func = ordering_func
self.reorder_on_append = reorder_on_append
|
'Synchronize ordering for the entire collection.
Sweeps through the list and ensures that each object has accurate
ordering information set.'
| def reorder(self):
| for (index, entity) in enumerate(self):
self._order_entity(index, entity, True)
|
'Append without any ordering behavior.'
| def _raw_append(self, entity):
| super(OrderingList, self).append(entity)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.