本文整理汇总了Python中sqlalchemy.orm.join方法的典型用法代码示例。如果您正苦于以下问题:Python orm.join方法的具体用法?Python orm.join怎么用?Python orm.join使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.orm
的用法示例。
在下文中一共展示了orm.join方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _splice_into_center
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import join [as 别名]
def _splice_into_center(self, other):
"""Splice a join into the center.
Given join(a, b) and join(b, c), return join(a, b).join(c)
"""
leftmost = other
while isinstance(leftmost, sql.Join):
leftmost = leftmost.left
assert self.right is leftmost
left = _ORMJoin(
self.left, other.left,
self.onclause, isouter=self.isouter,
_left_memo=self._left_memo,
_right_memo=other._left_memo
)
return _ORMJoin(
left,
other.right,
other.onclause, isouter=other.isouter,
_right_memo=other._right_memo
)
示例2: test_straight
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import join [as 别名]
def test_straight(self):
Company, Person, Manager, Engineer = self.classes(
"Company", "Person", "Manager", "Engineer"
)
stmt1 = select(Company).select_from(
orm_join(Company, Person, Company.employees)
)
stmt2 = select(Company).join(Company.employees)
stmt3 = (
Session()
.query(Company)
.join(Company.employees)
._final_statement(legacy_query_style=False)
)
self.assert_compile(stmt1, self.straight_company_to_person_expected)
self.assert_compile(stmt2, self.straight_company_to_person_expected)
self.assert_compile(stmt3, self.straight_company_to_person_expected)
示例3: test_straight_whereclause
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import join [as 别名]
def test_straight_whereclause(self):
Company, Person, Manager, Engineer = self.classes(
"Company", "Person", "Manager", "Engineer"
)
stmt1 = (
select(Company)
.select_from(orm_join(Company, Person, Company.employees))
.where(Person.name == "ed")
)
stmt2 = (
select(Company).join(Company.employees).where(Person.name == "ed")
)
stmt3 = (
Session()
.query(Company)
.join(Company.employees)
.filter(Person.name == "ed")
._final_statement(legacy_query_style=False)
)
self.assert_compile(stmt1, self.c_to_p_whereclause)
self.assert_compile(stmt2, self.c_to_p_whereclause)
self.assert_compile(stmt3, self.c_to_p_whereclause)
示例4: test_two_level
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import join [as 别名]
def test_two_level(self):
Company, Person, Paperwork = self.classes(
"Company", "Person", "Paperwork"
)
stmt1 = select(Company).select_from(
orm_join(Company, Person, Company.employees).join(
Paperwork, Person.paperwork
)
)
stmt2 = select(Company).join(Company.employees).join(Person.paperwork)
stmt3 = (
Session()
.query(Company)
.join(Company.employees)
.join(Person.paperwork)
._final_statement(legacy_query_style=False)
)
self.assert_compile(stmt1, self.person_paperwork_expected)
self.assert_compile(stmt2, self.person_paperwork_expected)
self.assert_compile(stmt3, self.person_paperwork_expected)
示例5: test_join_from_polymorphic_flag_aliased_one_future
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import join [as 别名]
def test_join_from_polymorphic_flag_aliased_one_future(self):
sess = create_session()
pa = aliased(Paperwork)
eq_(
sess.execute(
future_select(Person)
.order_by(Person.person_id)
.join(Person.paperwork.of_type(pa))
.filter(pa.description.like("%review%"))
)
.unique()
.scalars()
.all(),
[b1, m1],
)
示例6: test_join_from_with_polymorphic_nonaliased_one_future
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import join [as 别名]
def test_join_from_with_polymorphic_nonaliased_one_future(self):
sess = create_session()
pm = with_polymorphic(Person, [Manager])
eq_(
sess.execute(
future_select(pm)
.order_by(pm.person_id)
.join(pm.paperwork)
.filter(Paperwork.description.like("%review%"))
)
.unique()
.scalars()
.all(),
[b1, m1],
)
示例7: test_join_from_columns_or_subclass_three
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import join [as 别名]
def test_join_from_columns_or_subclass_three(self):
sess = create_session()
expected = [
("dilbert",),
("dilbert",),
("dogbert",),
("dogbert",),
("pointy haired boss",),
("vlad",),
("wally",),
("wally",),
]
eq_(
sess.query(Person.name)
.join(Paperwork, Person.paperwork)
.order_by(Person.name)
.all(),
expected,
)
示例8: test_join_from_columns_or_subclass_four
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import join [as 别名]
def test_join_from_columns_or_subclass_four(self):
sess = create_session()
# Load Person.name, joining from Person -> paperwork, get all
# the people.
expected = [
("dilbert",),
("dilbert",),
("dogbert",),
("dogbert",),
("pointy haired boss",),
("vlad",),
("wally",),
("wally",),
]
eq_(
sess.query(Person.name)
.join(paperwork, Person.person_id == paperwork.c.person_id)
.order_by(Person.name)
.all(),
expected,
)
示例9: __new__
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import join [as 别名]
def __new__(cls, value_list):
if isinstance(value_list, util.string_types) or value_list is None:
return cls.from_string(value_list)
values = set(value_list)
if values.difference(cls._allowed_cascades):
raise sa_exc.ArgumentError(
"Invalid cascade option(s): %s" %
", ".join([repr(x) for x in
sorted(values.difference(cls._allowed_cascades))]))
if "all" in values:
values.update(cls._add_w_all_cascades)
if "none" in values:
values.clear()
values.discard('all')
self = frozenset.__new__(CascadeOptions, values)
self.save_update = 'save-update' in values
self.delete = 'delete' in values
self.refresh_expire = 'refresh-expire' in values
self.merge = 'merge' in values
self.expunge = 'expunge' in values
self.delete_orphan = "delete-orphan" in values
if self.delete_orphan and not self.delete:
util.warn("The 'delete-orphan' cascade "
"option requires 'delete'.")
return self
示例10: __repr__
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import join [as 别名]
def __repr__(self):
return "CascadeOptions(%r)" % (
",".join([x for x in sorted(self)])
)
示例11: join
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import join [as 别名]
def join(self, right, onclause=None, isouter=False, join_to_left=None):
return _ORMJoin(self, right, onclause, isouter)
示例12: outerjoin
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import join [as 别名]
def outerjoin(left, right, onclause=None, join_to_left=None):
"""Produce a left outer join between left and right clauses.
This is the "outer join" version of the :func:`.orm.join` function,
featuring the same behavior except that an OUTER JOIN is generated.
See that function's documentation for other usage details.
"""
return _ORMJoin(left, right, onclause, True)
示例13: join
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import join [as 别名]
def join(
self, right, onclause=None,
isouter=False, full=False, join_to_left=None):
return _ORMJoin(self, right, onclause, full, isouter)
示例14: outerjoin
# 需要导入模块: from sqlalchemy import orm [as 别名]
# 或者: from sqlalchemy.orm import join [as 别名]
def outerjoin(left, right, onclause=None, full=False, join_to_left=None):
"""Produce a left outer join between left and right clauses.
This is the "outer join" version of the :func:`.orm.join` function,
featuring the same behavior except that an OUTER JOIN is generated.
See that function's documentation for other usage details.
"""
return _ORMJoin(left, right, onclause, True, full)