本文整理汇总了Python中sqlalchemy.orm.Load类的典型用法代码示例。如果您正苦于以下问题:Python Load类的具体用法?Python Load怎么用?Python Load使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Load类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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"])
)
开发者ID:23andMe,项目名称:sqlalchemy,代码行数:8,代码来源:test_options.py
示例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)))"
)
开发者ID:biroc,项目名称:sqlalchemy,代码行数:8,代码来源:test_options.py
示例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"])
)
开发者ID:biroc,项目名称:sqlalchemy,代码行数:9,代码来源:test_options.py
示例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])
)
开发者ID:23andMe,项目名称:sqlalchemy,代码行数:9,代码来源:test_options.py
示例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)
开发者ID:biroc,项目名称:sqlalchemy,代码行数:9,代码来源:test_options.py
示例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])
)
开发者ID:biroc,项目名称:sqlalchemy,代码行数:10,代码来源:test_options.py
示例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
}
)
开发者ID:biroc,项目名称:sqlalchemy,代码行数:11,代码来源:test_options.py
示例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
)
开发者ID:biroc,项目名称:sqlalchemy,代码行数:12,代码来源:test_options.py
示例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
)
开发者ID:biroc,项目名称:sqlalchemy,代码行数:12,代码来源:test_options.py
示例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"
)
开发者ID:biroc,项目名称:sqlalchemy,代码行数:12,代码来源:test_options.py
示例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
}
)
开发者ID:biroc,项目名称:sqlalchemy,代码行数:12,代码来源:test_options.py
示例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')),)
)
)
开发者ID:biroc,项目名称:sqlalchemy,代码行数:13,代码来源:test_options.py
示例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
)
开发者ID:biroc,项目名称:sqlalchemy,代码行数:13,代码来源:test_options.py
示例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
开发者ID:ianmcorvidae,项目名称:sir,代码行数:51,代码来源:searchentities.py
示例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)),
)
)
开发者ID:zhsj,项目名称:sqlalchemy,代码行数:14,代码来源:test_options.py
示例16: test_bound_cache_key_included_safe_w_option
def test_bound_cache_key_included_safe_w_option(self):
User, Address, Order, Item, SubItem = self.classes(
'User', 'Address', 'Order', 'Item', 'SubItem')
opt = Load(User).defaultload("orders").joinedload(
"items", innerjoin=True).defer("description")
query_path = self._make_path_registry([User, "orders"])
eq_(
opt._generate_cache_key(query_path),
(
(Order, 'items', Item,
('lazy', 'joined'), ('innerjoin', True)),
(Order, 'items', Item, 'description',
('deferred', True), ('instrument', True))
)
)
开发者ID:biroc,项目名称:sqlalchemy,代码行数:17,代码来源:test_options.py
示例17: test_query_opts_key_bound_branching
def test_query_opts_key_bound_branching(self):
A, B, C, D, E, F, G = self.classes('A', 'B', 'C', 'D', 'E', 'F', 'G')
base = Load(A).joinedload(A.bs)
opts = [
base.joinedload(B.cs),
base.joinedload(B.ds),
base.joinedload(B.es),
base.joinedload(B.fs)
]
q = Session().query(A)
@profiling.function_call_count()
def go():
q.options(*opts)
go()
开发者ID:cpcloud,项目名称:sqlalchemy,代码行数:17,代码来源:test_orm.py
示例18: test_generate_cache_key_bound_branching
def test_generate_cache_key_bound_branching(self):
A, B, C, D, E, F, G = self.classes('A', 'B', 'C', 'D', 'E', 'F', 'G')
base = Load(A).joinedload(A.bs)
opts = [
base.joinedload(B.cs),
base.joinedload(B.ds),
base.joinedload(B.es),
base.joinedload(B.fs)
]
cache_path = inspect(A)._path_registry
@profiling.function_call_count()
def go():
for opt in opts:
opt._generate_cache_key(cache_path)
go()
开发者ID:cpcloud,项目名称:sqlalchemy,代码行数:18,代码来源:test_orm.py
示例19: test_query_opts_key_bound_branching
def test_query_opts_key_bound_branching(self):
A, B, C, D, E, F, G = self.classes("A", "B", "C", "D", "E", "F", "G")
base = Load(A).joinedload(A.bs)
opts = [
base.joinedload(B.cs),
base.joinedload(B.ds),
base.joinedload(B.es),
base.joinedload(B.fs),
]
q = Session().query(A)
@profiling.function_call_count()
def go():
q.options(*opts)
go()
开发者ID:BY-jk,项目名称:sqlalchemy,代码行数:18,代码来源:test_orm.py
示例20: test_generate_cache_key_bound_branching
def test_generate_cache_key_bound_branching(self):
A, B, C, D, E, F, G = self.classes("A", "B", "C", "D", "E", "F", "G")
base = Load(A).joinedload(A.bs)
opts = [
base.joinedload(B.cs),
base.joinedload(B.ds),
base.joinedload(B.es),
base.joinedload(B.fs),
]
cache_path = inspect(A)._path_registry
@profiling.function_call_count()
def go():
for opt in opts:
opt._generate_cache_key(cache_path)
go()
开发者ID:BY-jk,项目名称:sqlalchemy,代码行数:19,代码来源:test_orm.py
注:本文中的sqlalchemy.orm.Load类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论