当前位置: 首页>>代码示例>>Python>>正文


Python sqlalchemy.outerjoin方法代码示例

本文整理汇总了Python中sqlalchemy.outerjoin方法的典型用法代码示例。如果您正苦于以下问题:Python sqlalchemy.outerjoin方法的具体用法?Python sqlalchemy.outerjoin怎么用?Python sqlalchemy.outerjoin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sqlalchemy的用法示例。


在下文中一共展示了sqlalchemy.outerjoin方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _create_outerjoin

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import outerjoin [as 别名]
def _create_outerjoin(cls, left, right, onclause=None):
        """Return an ``OUTER JOIN`` clause element.

        The returned object is an instance of :class:`.Join`.

        Similar functionality is also available via the
        :meth:`~.FromClause.outerjoin()` method on any
        :class:`.FromClause`.

        :param left: The left side of the join.

        :param right: The right side of the join.

        :param onclause:  Optional criterion for the ``ON`` clause, is
          derived from foreign key relationships established between
          left and right otherwise.

        To chain joins together, use the :meth:`.FromClause.join` or
        :meth:`.FromClause.outerjoin` methods on the resulting
        :class:`.Join` object.

        """
        return cls(left, right, onclause, isouter=True) 
开发者ID:jpush,项目名称:jbox,代码行数:25,代码来源:selectable.py

示例2: _create_outerjoin

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import outerjoin [as 别名]
def _create_outerjoin(cls, left, right, onclause=None, full=False):
        """Return an ``OUTER JOIN`` clause element.

        The returned object is an instance of :class:`.Join`.

        Similar functionality is also available via the
        :meth:`~.FromClause.outerjoin()` method on any
        :class:`.FromClause`.

        :param left: The left side of the join.

        :param right: The right side of the join.

        :param onclause:  Optional criterion for the ``ON`` clause, is
          derived from foreign key relationships established between
          left and right otherwise.

        To chain joins together, use the :meth:`.FromClause.join` or
        :meth:`.FromClause.outerjoin` methods on the resulting
        :class:`.Join` object.

        """
        return cls(left, right, onclause, isouter=True, full=full) 
开发者ID:yfauser,项目名称:planespotter,代码行数:25,代码来源:selectable.py

示例3: _create_outerjoin

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import outerjoin [as 别名]
def _create_outerjoin(cls, left, right, onclause=None, full=False):
        """Return an ``OUTER JOIN`` clause element.

        The returned object is an instance of :class:`_expression.Join`.

        Similar functionality is also available via the
        :meth:`_expression.FromClause.outerjoin` method on any
        :class:`_expression.FromClause`.

        :param left: The left side of the join.

        :param right: The right side of the join.

        :param onclause:  Optional criterion for the ``ON`` clause, is
          derived from foreign key relationships established between
          left and right otherwise.

        To chain joins together, use the :meth:`_expression.FromClause.join`
        or
        :meth:`_expression.FromClause.outerjoin` methods on the resulting
        :class:`_expression.Join` object.

        """
        return cls(left, right, onclause, isouter=True, full=full) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:26,代码来源:selectable.py

示例4: test_dslish

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import outerjoin [as 别名]
def test_dslish(self):
        """test the same as withjoinedload except using generative"""

        Thing, tests, options = (
            self.classes.Thing,
            self.tables.tests,
            self.tables.options,
        )

        s = create_session()
        q = s.query(Thing).options(sa.orm.joinedload("category"))
        result = q.filter(
            sa.and_(
                tests.c.owner_id == 1,
                sa.or_(
                    options.c.someoption == None,
                    options.c.someoption == False,  # noqa
                ),
            )
        ).outerjoin("owner_option")

        result_str = ["%d %s" % (t.id, t.category.name) for t in result]
        eq_(result_str, ["1 Some Category", "3 Some Category"]) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:25,代码来源:test_assorted_eager.py

示例5: test_nested_joins

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import outerjoin [as 别名]
def test_nested_joins(self):
        task, Task_Type, Joined, task_type, msg = (
            self.tables.task,
            self.classes.Task_Type,
            self.classes.Joined,
            self.tables.task_type,
            self.tables.msg,
        )

        # this is testing some subtle column resolution stuff,
        # concerning corresponding_column() being extremely accurate
        # as well as how mapper sets up its column properties

        mapper(Task_Type, task_type)

        j = sa.outerjoin(task, msg, task.c.id == msg.c.task_id)
        jj = sa.select(
            [
                task.c.id.label("task_id"),
                sa.func.count(msg.c.id).label("props_cnt"),
            ],
            from_obj=[j],
            group_by=[task.c.id],
        ).alias("prop_c_s")
        jjj = sa.join(task, jj, task.c.id == jj.c.task_id)

        mapper(
            Joined,
            jjj,
            properties=dict(type=relationship(Task_Type, lazy="joined")),
        )

        session = create_session()

        eq_(
            session.query(Joined).limit(10).offset(0).one(),
            Joined(id=1, title="task 1", props_cnt=0),
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:40,代码来源:test_assorted_eager.py

示例6: outerjoin

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import outerjoin [as 别名]
def outerjoin(self, right, onclause=None):
        """Return a :class:`.Join` from this :class:`.FromClause`
        to another :class:`FromClause`, with the "isouter" flag set to
        True.

        E.g.::

            from sqlalchemy import outerjoin

            j = user_table.outerjoin(address_table,
                            user_table.c.id == address_table.c.user_id)

        The above is equivalent to::

            j = user_table.join(
                address_table,
                user_table.c.id == address_table.c.user_id,
                isouter=True)

        :param right: the right side of the join; this is any
         :class:`.FromClause` object such as a :class:`.Table` object, and
         may also be a selectable-compatible object such as an ORM-mapped
         class.

        :param onclause: a SQL expression representing the ON clause of the
         join.  If left at ``None``, :meth:`.FromClause.join` will attempt to
         join the two tables based on a foreign key relationship.

        .. seealso::

            :meth:`.FromClause.join`

            :class:`.Join`

        """

        return Join(self, right, onclause, True) 
开发者ID:jpush,项目名称:jbox,代码行数:39,代码来源:selectable.py

示例7: outerjoin

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import outerjoin [as 别名]
def outerjoin(self, *arg, **kw):
        return self._implicit_subquery.outerjoin(*arg, **kw) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:4,代码来源:selectable.py

示例8: test_join_against_join

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import outerjoin [as 别名]
def test_join_against_join(self):
        j = outerjoin(table1, table2, table1.c.col1 == table2.c.col2)
        jj = select([table1.c.col1.label("bar_col1")], from_obj=[j]).alias(
            "foo"
        )
        jjj = join(table1, jj, table1.c.col1 == jj.c.bar_col1)
        assert jjj.corresponding_column(jjj.c.table1_col1) is jjj.c.table1_col1
        j2 = jjj.alias("foo")
        assert j2.corresponding_column(jjj.c.table1_col1) is j2.c.table1_col1
        assert jjj.corresponding_column(jj.c.bar_col1) is jj.c.bar_col1 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:12,代码来源:test_selectable.py

示例9: test_withoutjoinedload

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import outerjoin [as 别名]
def test_withoutjoinedload(self):
        Thing, tests, options = (
            self.classes.Thing,
            self.tables.tests,
            self.tables.options,
        )

        s = create_session()
        result = (
            s.query(Thing)
            .select_from(
                tests.outerjoin(
                    options,
                    sa.and_(
                        tests.c.id == options.c.test_id,
                        tests.c.owner_id == options.c.owner_id,
                    ),
                )
            )
            .filter(
                sa.and_(
                    tests.c.owner_id == 1,
                    sa.or_(
                        options.c.someoption == None,  # noqa
                        options.c.someoption == False,
                    ),
                )
            )
        )

        result_str = ["%d %s" % (t.id, t.category.name) for t in result]
        eq_(result_str, ["1 Some Category", "3 Some Category"]) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:34,代码来源:test_assorted_eager.py

示例10: test_withjoinedload

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import outerjoin [as 别名]
def test_withjoinedload(self):
        """
        Test that an joinedload locates the correct "from" clause with which to
        attach to, when presented with a query that already has a complicated
        from clause.

        """

        Thing, tests, options = (
            self.classes.Thing,
            self.tables.tests,
            self.tables.options,
        )

        s = create_session()
        q = s.query(Thing).options(sa.orm.joinedload("category"))

        result = q.select_from(
            tests.outerjoin(
                options,
                sa.and_(
                    tests.c.id == options.c.test_id,
                    tests.c.owner_id == options.c.owner_id,
                ),
            )
        ).filter(
            sa.and_(
                tests.c.owner_id == 1,
                sa.or_(
                    options.c.someoption == None,
                    options.c.someoption == False,  # noqa
                ),
            )
        )

        result_str = ["%d %s" % (t.id, t.category.name) for t in result]
        eq_(result_str, ["1 Some Category", "3 Some Category"]) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:39,代码来源:test_assorted_eager.py

示例11: outerjoin

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import outerjoin [as 别名]
def outerjoin(self, right, onclause=None):
        """Return a :class:`.Join` from this :class:`.FromClause`
        to another :class:`FromClause`, with the "isouter" flag set to
        True.

        E.g.::

            from sqlalchemy import outerjoin

            j = user_table.outerjoin(address_table,
                            user_table.c.id == address_table.c.user_id)

        The above is equivalent to::

            j = user_table.join(address_table,
                            user_table.c.id == address_table.c.user_id, isouter=True)

        :param right: the right side of the join; this is any :class:`.FromClause`
         object such as a :class:`.Table` object, and may also be a selectable-compatible
         object such as an ORM-mapped class.

        :param onclause: a SQL expression representing the ON clause of the
         join.  If left at ``None``, :meth:`.FromClause.join` will attempt to
         join the two tables based on a foreign key relationship.

        .. seealso::

            :meth:`.FromClause.join`

            :class:`.Join`

        """

        return Join(self, right, onclause, True) 
开发者ID:binhex,项目名称:moviegrabber,代码行数:36,代码来源:selectable.py

示例12: outerjoin

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import outerjoin [as 别名]
def outerjoin(self, right, onclause=None, full=False):
        """Return a :class:`.Join` from this :class:`.FromClause`
        to another :class:`FromClause`, with the "isouter" flag set to
        True.

        E.g.::

            from sqlalchemy import outerjoin

            j = user_table.outerjoin(address_table,
                            user_table.c.id == address_table.c.user_id)

        The above is equivalent to::

            j = user_table.join(
                address_table,
                user_table.c.id == address_table.c.user_id,
                isouter=True)

        :param right: the right side of the join; this is any
         :class:`.FromClause` object such as a :class:`.Table` object, and
         may also be a selectable-compatible object such as an ORM-mapped
         class.

        :param onclause: a SQL expression representing the ON clause of the
         join.  If left at ``None``, :meth:`.FromClause.join` will attempt to
         join the two tables based on a foreign key relationship.

        :param full: if True, render a FULL OUTER JOIN, instead of
         LEFT OUTER JOIN.

         .. versionadded:: 1.1

        .. seealso::

            :meth:`.FromClause.join`

            :class:`.Join`

        """

        return Join(self, right, onclause, True, full) 
开发者ID:yfauser,项目名称:planespotter,代码行数:44,代码来源:selectable.py

示例13: test_reduce_aliased_join

# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import outerjoin [as 别名]
def test_reduce_aliased_join(self):
        metadata = MetaData()
        people = Table(
            "people",
            metadata,
            Column(
                "person_id",
                Integer,
                Sequence("person_id_seq", optional=True),
                primary_key=True,
            ),
            Column("name", String(50)),
            Column("type", String(30)),
        )
        engineers = Table(
            "engineers",
            metadata,
            Column(
                "person_id",
                Integer,
                ForeignKey("people.person_id"),
                primary_key=True,
            ),
            Column("status", String(30)),
            Column("engineer_name", String(50)),
            Column("primary_language", String(50)),
        )
        managers = Table(
            "managers",
            metadata,
            Column(
                "person_id",
                Integer,
                ForeignKey("people.person_id"),
                primary_key=True,
            ),
            Column("status", String(30)),
            Column("manager_name", String(50)),
        )
        pjoin = (
            people.outerjoin(engineers)
            .outerjoin(managers)
            .select()
            .apply_labels()
            .alias("pjoin")
        )
        eq_(
            util.column_set(
                sql_util.reduce_columns(
                    [
                        pjoin.c.people_person_id,
                        pjoin.c.engineers_person_id,
                        pjoin.c.managers_person_id,
                    ]
                )
            ),
            util.column_set([pjoin.c.people_person_id]),
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:60,代码来源:test_selectable.py


注:本文中的sqlalchemy.outerjoin方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。