本文整理汇总了Python中sqlalchemy.orm.Load类的典型用法代码示例。如果您正苦于以下问题:Python Load类的具体用法?Python Load怎么用?Python Load使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Load类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_gen_path_string_column
def test_gen_path_string_column(self):
User = self.classes.User
l = Load(User)
eq_(
l._generate_path(inspect(User)._path_registry, "name", "column"),
self._make_path_registry([User, "name"])
)
示例2: test_str
def test_str(self):
User = self.classes.User
result = Load(User)
result.strategy = (('deferred', False), ('instrument', True))
eq_(
str(result),
"Load(strategy=(('deferred', False), ('instrument', True)))"
)
示例3: test_gen_path_attr_column
def test_gen_path_attr_column(self):
User = self.classes.User
result = Load(User)
eq_(
result._generate_path(inspect(User)._path_registry,
User.name, "column"),
self._make_path_registry([User, "name"])
)
示例4: test_gen_path_string_entity
def test_gen_path_string_entity(self):
User = self.classes.User
Address = self.classes.Address
l = Load(User)
eq_(
l._generate_path(inspect(User)._path_registry, "addresses", "relationship"),
self._make_path_registry([User, "addresses", Address])
)
示例5: test_gen_path_attr_entity_invalid_noraiseerr
def test_gen_path_attr_entity_invalid_noraiseerr(self):
User = self.classes.User
Order = self.classes.Order
result = Load(User)
eq_(result._generate_path(inspect(User)._path_registry, Order.items,
"relationship", False),
None)
示例6: test_gen_path_attr_entity
def test_gen_path_attr_entity(self):
User = self.classes.User
Address = self.classes.Address
result = Load(User)
eq_(
result._generate_path(inspect(User)._path_registry,
User.addresses, "relationship"),
self._make_path_registry([User, "addresses", Address])
)
示例7: test_set_strat_ent
def test_set_strat_ent(self):
User = self.classes.User
l1 = Load(User)
l2 = l1.joinedload("addresses")
eq_(
l1.context,
{
('loader', self._make_path([User, "addresses"])): l2
}
)
示例8: test_bound_cache_key_excluded_on_other
def test_bound_cache_key_excluded_on_other(self):
User, Address, Order, Item, SubItem = self.classes(
'User', 'Address', 'Order', 'Item', 'SubItem')
query_path = self._make_path_registry(
[User, "addresses"])
opt = Load(User).joinedload(User.orders).joinedload(Order.items)
eq_(
opt._generate_cache_key(query_path),
None
)
示例9: test_bound_cache_key_included_unsafe_option_three
def test_bound_cache_key_included_unsafe_option_three(self):
User, Address, Order, Item, SubItem = self.classes(
'User', 'Address', 'Order', 'Item', 'SubItem')
query_path = self._make_path_registry([User, "orders", Order, "items"])
opt = Load(User).joinedload(User.orders).\
joinedload(Order.items.of_type(aliased(SubItem)))
eq_(
opt._generate_cache_key(query_path),
False
)
示例10: test_gen_path_invalid_from_col
def test_gen_path_invalid_from_col(self):
User = self.classes.User
result = Load(User)
result.path = self._make_path_registry([User, "name"])
assert_raises_message(
sa.exc.ArgumentError,
"Attribute 'name' of entity 'Mapper|User|users' does "
"not refer to a mapped entity",
result._generate_path, result.path, User.addresses, "relationship"
)
示例11: test_set_strat_col
def test_set_strat_col(self):
User = self.classes.User
l1 = Load(User)
l2 = l1.defer("name")
l3 = list(l2.context.values())[0]
eq_(
l1.context,
{
('loader', self._make_path([User, "name"])): l3
}
)
示例12: test_bound_cache_key_included_safe
def test_bound_cache_key_included_safe(self):
User, Address, Order, Item, SubItem = self.classes(
'User', 'Address', 'Order', 'Item', 'SubItem')
query_path = self._make_path_registry([User, "orders"])
opt = Load(User).joinedload(User.orders).joinedload(Order.items)
eq_(
opt._generate_cache_key(query_path),
(
((Order, 'items', Item, ('lazy', 'joined')),)
)
)
示例13: test_bound_cache_key_included_unsafe_query
def test_bound_cache_key_included_unsafe_query(self):
User, Address, Order, Item, SubItem = self.classes(
'User', 'Address', 'Order', 'Item', 'SubItem')
au = aliased(User)
query_path = self._make_path_registry([inspect(au), "orders"])
opt = Load(au).joinedload(au.orders).\
joinedload(Order.items)
eq_(
opt._generate_cache_key(query_path),
False
)
示例14: build_entity_query
def build_entity_query(self):
"""
Builds a :class:`sqla:sqlalchemy.orm.query.Query` object for this
entity (an instance of :class:`sir.schema.searchentities.SearchEntity`)
that eagerly loads the values of all search fields.
:rtype: :class:`sqla:sqlalchemy.orm.query.Query`
"""
root_model = self.model
query = Query(root_model)
paths = [field.paths for field in self.fields]
if (config.CFG.getboolean("sir", "wscompat")
and self.extrapaths is not None):
paths.extend([self.extrapaths])
merged_paths = merge_paths(paths)
for field_paths in paths:
for path in field_paths:
current_merged_path = merged_paths
model = root_model
load = Load(model)
split_path = path.split(".")
for pathelem in split_path:
current_merged_path = current_merged_path[pathelem]
column = getattr(model, pathelem)
prop = column.property
if isinstance(prop, RelationshipProperty):
pk = column.mapper.primary_key[0].name
if prop.direction == ONETOMANY:
load = load.subqueryload(pathelem)
elif prop.direction == MANYTOONE:
load = load.joinedload(pathelem)
else:
load = load.defaultload(pathelem)
required_columns = current_merged_path.keys()
required_columns.append(pk)
# Get the mapper class of the current element of the path so
# the next iteration can access it.
model = prop.mapper.class_
logger.debug("Loading only %s on %s",
required_columns,
model)
load = defer_everything_but(class_mapper(model),
load,
*required_columns)
query = query.options(load)
return query
示例15: test_bound_cache_key_undefer_group
def test_bound_cache_key_undefer_group(self):
User, Address = self.classes('User', 'Address')
query_path = self._make_path_registry([User, "addresses"])
opt = Load(User).defaultload(User.addresses).undefer_group('xyz')
eq_(
opt._generate_cache_key(query_path),
(
(Address, 'column:*', ("undefer_group_xyz", True)),
)
)