本文整理汇总了Python中sqlalchemy.orm.util.state_attribute_str函数的典型用法代码示例。如果您正苦于以下问题:Python state_attribute_str函数的具体用法?Python state_attribute_str怎么用?Python state_attribute_str使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了state_attribute_str函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: create_row_processor
def create_row_processor(self, selectcontext, path, mapper, row, adapter):
if not self.is_class_level:
def new_execute(state, dict_, row, **flags):
# we are not the primary manager for this attribute on this class - set up a
# per-instance lazyloader, which will override the class-level behavior.
# this currently only happens when using a "lazyload" option on a "no load"
# attribute - "eager" attributes always have a class-level lazyloader
# installed.
self._init_instance_attribute(state, callable_=LoadLazyAttribute(state, self.key))
if self._should_log_debug:
new_execute = self.debug_callable(new_execute, self.logger, None,
lambda state, dict_, row, **flags: "set instance-level lazy loader on %s" % \
mapperutil.state_attribute_str(state,
self.key)
)
return (new_execute, None)
else:
def new_execute(state, dict_, row, **flags):
# we are the primary manager for this attribute on this class - reset its
# per-instance attribute state, so that the class-level lazy loader is
# executed when next referenced on this instance. this is needed in
# populate_existing() types of scenarios to reset any existing state.
state.reset(self.key, dict_)
if self._should_log_debug:
new_execute = self.debug_callable(new_execute, self.logger, None,
lambda state, dict_, row, **flags: "set class-level lazy loader on %s" % \
mapperutil.state_attribute_str(state,
self.key)
)
return (new_execute, None)
开发者ID:agbiotec,项目名称:galaxy-tools-vcr,代码行数:34,代码来源:strategies.py
示例2: create_row_processor
def create_row_processor(self, selectcontext, path, mapper, row, adapter):
col = self.columns[0]
if adapter:
col = adapter.columns[col]
if col in row:
return self.parent_property._get_strategy(ColumnLoader).create_row_processor(
selectcontext, path, mapper, row, adapter
)
elif not self.is_class_level or len(selectcontext.options):
def new_execute(state, row, **flags):
state.set_callable(self.key, self.setup_loader(state))
else:
def new_execute(state, row, **flags):
state.reset(self.key)
if self._should_log_debug:
new_execute = self.debug_callable(
new_execute,
self.logger,
None,
lambda state, row, **flags: "set deferred callable on %s"
% mapperutil.state_attribute_str(state, self.key),
)
return (new_execute, None)
开发者ID:blaxter,项目名称:my-gozerbot,代码行数:28,代码来源:strategies.py
示例3: __call__
def __call__(self):
state = self.state
if not mapper._state_has_identity(state):
return None
instance_mapper = mapper._state_mapper(state)
prop = instance_mapper.get_property(self.key)
strategy = prop._get_strategy(LazyLoader)
if strategy._should_log_debug:
strategy.logger.debug("loading %s" % mapperutil.state_attribute_str(state, self.key))
session = sessionlib._state_session(state)
if session is None:
raise sa_exc.UnboundExecutionError(
"Parent instance %s is not bound to a Session; "
"lazy load operation of attribute '%s' cannot proceed" %
(mapperutil.state_str(state), self.key)
)
q = session.query(prop.mapper)._adapt_all_clauses()
if self.path:
q = q._with_current_path(self.path)
# if we have a simple primary key load, use mapper.get()
# to possibly save a DB round trip
if strategy.use_get:
ident = []
allnulls = True
for primary_key in prop.mapper.primary_key:
val = instance_mapper._get_committed_state_attr_by_column(state, strategy._equated_columns[primary_key])
allnulls = allnulls and val is None
ident.append(val)
if allnulls:
return None
if self.options:
q = q._conditional_options(*self.options)
return q.get(ident)
if prop.order_by:
q = q.order_by(*util.to_list(prop.order_by))
if self.options:
q = q._conditional_options(*self.options)
q = q.filter(strategy.lazy_clause(state))
result = q.all()
if strategy.uselist:
return result
else:
if result:
return result[0]
else:
return None
开发者ID:AntonNguyen,项目名称:easy_api,代码行数:55,代码来源:strategies.py
示例4: __call__
def __call__(self, **kw):
if kw.get('passive') is attributes.PASSIVE_NO_FETCH:
return attributes.PASSIVE_NO_RESULT
state = self.state
localparent = mapper._state_mapper(state)
prop = localparent.get_property(self.key)
strategy = prop._get_strategy(DeferredColumnLoader)
if strategy.group:
toload = [
p.key for p in
localparent.iterate_properties
if isinstance(p, StrategizedProperty) and
isinstance(p.strategy, DeferredColumnLoader) and
p.group==strategy.group
]
else:
toload = [self.key]
# narrow the keys down to just those which have no history
group = [k for k in toload if k in state.unmodified]
if strategy._should_log_debug():
strategy.logger.debug(
"deferred load %s group %s",
(mapperutil.state_attribute_str(state, self.key),
group and ','.join(group) or 'None')
)
session = sessionlib._state_session(state)
if session is None:
raise orm_exc.DetachedInstanceError(
"Parent instance %s is not bound to a Session; "
"deferred load operation of attribute '%s' cannot proceed" %
(mapperutil.state_str(state), self.key)
)
query = session.query(localparent)
ident = state.key[1]
query._get(None, ident=ident,
only_load_props=group, refresh_state=state)
return attributes.ATTR_WAS_SET
开发者ID:jsmiller84,项目名称:CouchPotato,代码行数:45,代码来源:strategies.py
示例5: __call__
def __call__(self):
state = self.state
if not mapper._state_has_identity(state):
return None
localparent = mapper._state_mapper(state)
prop = localparent.get_property(self.key)
strategy = prop._get_strategy(DeferredColumnLoader)
if self.keys:
toload = self.keys
elif strategy.group:
toload = [
p.key
for p in localparent.iterate_properties
if isinstance(p, StrategizedProperty)
and isinstance(p.strategy, DeferredColumnLoader)
and p.group == strategy.group
]
else:
toload = [self.key]
# narrow the keys down to just those which have no history
group = [k for k in toload if k in state.unmodified]
if strategy._should_log_debug:
strategy.logger.debug(
"deferred load %s group %s"
% (mapperutil.state_attribute_str(state, self.key), group and ",".join(group) or "None")
)
session = sessionlib._state_session(state)
if session is None:
raise sa_exc.UnboundExecutionError(
"Parent instance %s is not bound to a Session; deferred load operation of attribute '%s' cannot proceed"
% (mapperutil.state_str(state), self.key)
)
query = session.query(localparent)
ident = state.key[1]
query._get(None, ident=ident, only_load_props=group, refresh_state=state)
return attributes.ATTR_WAS_SET
开发者ID:blaxter,项目名称:my-gozerbot,代码行数:44,代码来源:strategies.py
示例6: create_row_processor
def create_row_processor(self, selectcontext, path, mapper, row, adapter):
col = self.columns[0]
if adapter:
col = adapter.columns[col]
if col in row:
return self.parent_property._get_strategy(ColumnLoader).create_row_processor(selectcontext, path, mapper, row, adapter)
elif not self.is_class_level:
def new_execute(state, dict_, row, **flags):
state.set_callable(self.key, LoadDeferredColumns(state, self.key))
else:
def new_execute(state, dict_, row, **flags):
# reset state on the key so that deferred callables
# fire off on next access.
state.reset(self.key, dict_)
if self._should_log_debug:
new_execute = self.debug_callable(new_execute, self.logger, None,
lambda state, row, **flags: "set deferred callable on %s" % mapperutil.state_attribute_str(state, self.key)
)
return (new_execute, None)
开发者ID:harryd,项目名称:xsbs-minimal,代码行数:21,代码来源:strategies.py
示例7: __call__
def __call__(self, **kw):
state = self.state
instance_mapper = mapper._state_mapper(state)
prop = instance_mapper.get_property(self.key)
strategy = prop._get_strategy(LazyLoader)
if kw.get("passive") is attributes.PASSIVE_NO_FETCH and not strategy.use_get:
return attributes.PASSIVE_NO_RESULT
if strategy._should_log_debug():
strategy.logger.debug("loading %s", mapperutil.state_attribute_str(state, self.key))
session = sessionlib._state_session(state)
if session is None:
raise orm_exc.DetachedInstanceError(
"Parent instance %s is not bound to a Session; "
"lazy load operation of attribute '%s' cannot proceed" % (mapperutil.state_str(state), self.key)
)
q = session.query(prop.mapper)._adapt_all_clauses()
if state.load_path:
q = q._with_current_path(state.load_path + (self.key,))
# if we have a simple primary key load, use mapper.get()
# to possibly save a DB round trip
if strategy.use_get:
ident = []
allnulls = True
for primary_key in prop.mapper.primary_key:
val = instance_mapper._get_committed_state_attr_by_column(
state, state.dict, strategy._equated_columns[primary_key], **kw
)
if val is attributes.PASSIVE_NO_RESULT:
return val
allnulls = allnulls and val is None
ident.append(val)
if allnulls:
return None
if state.load_options:
q = q._conditional_options(*state.load_options)
key = prop.mapper.identity_key_from_primary_key(ident)
return q._get(key, ident, **kw)
if prop.order_by:
q = q.order_by(*util.to_list(prop.order_by))
for rev in prop._reverse_property:
# reverse props that are MANYTOONE are loading *this*
# object from get(), so don't need to eager out to those.
if rev.direction is interfaces.MANYTOONE and rev._use_get and not isinstance(rev.strategy, LazyLoader):
q = q.options(EagerLazyOption(rev.key, lazy="select"))
if state.load_options:
q = q._conditional_options(*state.load_options)
q = q.filter(strategy.lazy_clause(state))
result = q.all()
if strategy.uselist:
return result
else:
l = len(result)
if l:
if l > 1:
util.warn("Multiple rows returned with " "uselist=False for lazily-loaded attribute '%s' " % prop)
return result[0]
else:
return None
开发者ID:blitzmann,项目名称:Pyfa-skel,代码行数:73,代码来源:strategies.py
注:本文中的sqlalchemy.orm.util.state_attribute_str函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论