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


Python util.ClauseAdapter方法代码示例

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


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

示例1: test_whereclause_adapted

# 需要导入模块: from sqlalchemy.sql import util [as 别名]
# 或者: from sqlalchemy.sql.util import ClauseAdapter [as 别名]
def test_whereclause_adapted(self):
        table1 = table("t1", column("a"))

        s1 = select([table1]).subquery()

        s2 = select([s1]).where(s1.c.a == 5)

        assert s2._whereclause.left.table is s1

        ta = select([table1]).subquery()

        s3 = sql_util.ClauseAdapter(ta).traverse(s2)

        froms = list(s3._iterate_from_elements())

        assert s1 not in froms

        # these are new assumptions with the newer approach that
        # actively swaps out whereclause and others
        assert s3._whereclause.left.table is not s1
        assert s3._whereclause.left.table in froms 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:23,代码来源:test_selectable.py

示例2: test_this_thing

# 需要导入模块: from sqlalchemy.sql import util [as 别名]
# 或者: from sqlalchemy.sql.util import ClauseAdapter [as 别名]
def test_this_thing(self):
        s = select([t1]).where(t1.c.col1 == "foo").alias()
        s2 = select([s.c.col1])

        self.assert_compile(
            s2,
            "SELECT anon_1.col1 FROM (SELECT "
            "table1.col1 AS col1, table1.col2 AS col2, "
            "table1.col3 AS col3 FROM table1 WHERE "
            "table1.col1 = :col1_1) AS anon_1",
        )
        t1a = t1.alias()
        s2 = sql_util.ClauseAdapter(t1a).traverse(s2)
        self.assert_compile(
            s2,
            "SELECT anon_1.col1 FROM (SELECT "
            "table1_1.col1 AS col1, table1_1.col2 AS "
            "col2, table1_1.col3 AS col3 FROM table1 "
            "AS table1_1 WHERE table1_1.col1 = "
            ":col1_1) AS anon_1",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:23,代码来源:test_external_traversal.py

示例3: test_this_thing_using_setup_joins_one

# 需要导入模块: from sqlalchemy.sql import util [as 别名]
# 或者: from sqlalchemy.sql.util import ClauseAdapter [as 别名]
def test_this_thing_using_setup_joins_one(self):
        s = (
            future_select(t1)
            .join_from(t1, t2, t1.c.col1 == t2.c.col2)
            .subquery()
        )
        s2 = future_select(s.c.col1).join_from(t3, s, t3.c.col2 == s.c.col1)

        self.assert_compile(
            s2,
            "SELECT anon_1.col1 FROM table3 JOIN (SELECT table1.col1 AS "
            "col1, table1.col2 AS col2, table1.col3 AS col3 FROM table1 "
            "JOIN table2 ON table1.col1 = table2.col2) AS anon_1 "
            "ON table3.col2 = anon_1.col1",
        )
        t1a = t1.alias()
        s2 = sql_util.ClauseAdapter(t1a).traverse(s2)
        self.assert_compile(
            s2,
            "SELECT anon_1.col1 FROM table3 JOIN (SELECT table1_1.col1 AS "
            "col1, table1_1.col2 AS col2, table1_1.col3 AS col3 "
            "FROM table1 AS table1_1 JOIN table2 ON table1_1.col1 = "
            "table2.col2) AS anon_1 ON table3.col2 = anon_1.col1",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:26,代码来源:test_external_traversal.py

示例4: test_select_setup_joins_adapt_element_two

# 需要导入模块: from sqlalchemy.sql import util [as 别名]
# 或者: from sqlalchemy.sql.util import ClauseAdapter [as 别名]
def test_select_setup_joins_adapt_element_two(self):
        s = future_select(literal_column("1")).join_from(
            t1, t2, t1.c.col1 == t2.c.col2
        )

        t1a = t1.alias()

        s2 = sql_util.ClauseAdapter(t1a).traverse(s)

        self.assert_compile(
            s, "SELECT 1 FROM table1 JOIN table2 ON table1.col1 = table2.col2"
        )
        self.assert_compile(
            s2,
            "SELECT 1 FROM table1 AS table1_1 "
            "JOIN table2 ON table1_1.col1 = table2.col2",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:19,代码来源:test_external_traversal.py

示例5: test_select_setup_joins_adapt_element_three

# 需要导入模块: from sqlalchemy.sql import util [as 别名]
# 或者: from sqlalchemy.sql.util import ClauseAdapter [as 别名]
def test_select_setup_joins_adapt_element_three(self):
        s = future_select(literal_column("1")).join_from(
            t1, t2, t1.c.col1 == t2.c.col2
        )

        t2a = t2.alias()

        s2 = sql_util.ClauseAdapter(t2a).traverse(s)

        self.assert_compile(
            s, "SELECT 1 FROM table1 JOIN table2 ON table1.col1 = table2.col2"
        )
        self.assert_compile(
            s2,
            "SELECT 1 FROM table1 "
            "JOIN table2 AS table2_1 ON table1.col1 = table2_1.col2",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:19,代码来源:test_external_traversal.py

示例6: test_joins_dont_adapt

# 需要导入模块: from sqlalchemy.sql import util [as 别名]
# 或者: from sqlalchemy.sql.util import ClauseAdapter [as 别名]
def test_joins_dont_adapt(self):
        # adapting to a join, i.e. ClauseAdapter(t1.join(t2)), doesn't
        # make much sense. ClauseAdapter doesn't make any changes if
        # it's against a straight join.

        users = table("users", column("id"))
        addresses = table("addresses", column("id"), column("user_id"))

        ualias = users.alias()

        s = select(
            [func.count(addresses.c.id)], users.c.id == addresses.c.user_id
        ).correlate(users)
        s = sql_util.ClauseAdapter(ualias).traverse(s)

        j1 = addresses.join(ualias, addresses.c.user_id == ualias.c.id)

        self.assert_compile(
            sql_util.ClauseAdapter(j1).traverse(s),
            "SELECT count(addresses.id) AS count_1 "
            "FROM addresses WHERE users_1.id = "
            "addresses.user_id",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:25,代码来源:test_external_traversal.py

示例7: test_table_to_alias_5

# 需要导入模块: from sqlalchemy.sql import util [as 别名]
# 或者: from sqlalchemy.sql.util import ClauseAdapter [as 别名]
def test_table_to_alias_5(self):
        t1alias = t1.alias("t1alias")
        vis = sql_util.ClauseAdapter(t1alias)
        self.assert_compile(
            select([t1alias, t2]).where(
                t1alias.c.col1
                == vis.traverse(
                    select(
                        [literal_column("*")],
                        t1.c.col1 == t2.c.col2,
                        from_obj=[t1, t2],
                    )
                    .correlate(t1)
                    .scalar_subquery()
                )
            ),
            "SELECT t1alias.col1, t1alias.col2, t1alias.col3, "
            "table2.col1, table2.col2, table2.col3 "
            "FROM table1 AS t1alias, table2 WHERE t1alias.col1 = "
            "(SELECT * FROM table2 WHERE t1alias.col1 = table2.col2)",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:23,代码来源:test_external_traversal.py

示例8: test_table_to_alias_6

# 需要导入模块: from sqlalchemy.sql import util [as 别名]
# 或者: from sqlalchemy.sql.util import ClauseAdapter [as 别名]
def test_table_to_alias_6(self):
        t1alias = t1.alias("t1alias")
        vis = sql_util.ClauseAdapter(t1alias)
        self.assert_compile(
            select([t1alias, t2]).where(
                t1alias.c.col1
                == vis.traverse(
                    select(
                        [literal_column("*")],
                        t1.c.col1 == t2.c.col2,
                        from_obj=[t1, t2],
                    )
                    .correlate(t2)
                    .scalar_subquery()
                )
            ),
            "SELECT t1alias.col1, t1alias.col2, t1alias.col3, "
            "table2.col1, table2.col2, table2.col3 "
            "FROM table1 AS t1alias, table2 "
            "WHERE t1alias.col1 = "
            "(SELECT * FROM table1 AS t1alias "
            "WHERE t1alias.col1 = table2.col2)",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:25,代码来源:test_external_traversal.py

示例9: test_table_to_alias_15

# 需要导入模块: from sqlalchemy.sql import util [as 别名]
# 或者: from sqlalchemy.sql.util import ClauseAdapter [as 别名]
def test_table_to_alias_15(self):
        t1alias = t1.alias("t1alias")
        vis = sql_util.ClauseAdapter(t1alias)
        t2alias = t2.alias("t2alias")
        vis.chain(sql_util.ClauseAdapter(t2alias))
        self.assert_compile(
            select([t1alias, t2alias]).where(
                t1alias.c.col1
                == vis.traverse(
                    select(["*"], t1.c.col1 == t2.c.col2, from_obj=[t1, t2])
                    .correlate(t1)
                    .scalar_subquery()
                )
            ),
            "SELECT t1alias.col1, t1alias.col2, t1alias.col3, "
            "t2alias.col1, t2alias.col2, t2alias.col3 "
            "FROM table1 AS t1alias, table2 AS t2alias "
            "WHERE t1alias.col1 = "
            "(SELECT * FROM table2 AS t2alias "
            "WHERE t1alias.col1 = t2alias.col2)",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:23,代码来源:test_external_traversal.py

示例10: test_table_to_alias_16

# 需要导入模块: from sqlalchemy.sql import util [as 别名]
# 或者: from sqlalchemy.sql.util import ClauseAdapter [as 别名]
def test_table_to_alias_16(self):
        t1alias = t1.alias("t1alias")
        vis = sql_util.ClauseAdapter(t1alias)
        t2alias = t2.alias("t2alias")
        vis.chain(sql_util.ClauseAdapter(t2alias))
        self.assert_compile(
            t2alias.select().where(
                t2alias.c.col2
                == vis.traverse(
                    select(["*"], t1.c.col1 == t2.c.col2, from_obj=[t1, t2])
                    .correlate(t2)
                    .scalar_subquery()
                )
            ),
            "SELECT t2alias.col1, t2alias.col2, t2alias.col3 "
            "FROM table2 AS t2alias WHERE t2alias.col2 = "
            "(SELECT * FROM table1 AS t1alias WHERE "
            "t1alias.col1 = t2alias.col2)",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:21,代码来源:test_external_traversal.py

示例11: test_aliasedselect_to_aliasedselect_join

# 需要导入模块: from sqlalchemy.sql import util [as 别名]
# 或者: from sqlalchemy.sql.util import ClauseAdapter [as 别名]
def test_aliasedselect_to_aliasedselect_join(self):
        s1 = select([t1]).alias("foo")
        s2 = select([s1]).limit(5).offset(10).alias()
        j = s1.outerjoin(t2, s1.c.col1 == t2.c.col1)
        self.assert_compile(
            sql_util.ClauseAdapter(s2).traverse(j).select(),
            "SELECT anon_1.col1, anon_1.col2, "
            "anon_1.col3, table2.col1, table2.col2, "
            "table2.col3 FROM (SELECT foo.col1 AS "
            "col1, foo.col2 AS col2, foo.col3 AS col3 "
            "FROM (SELECT table1.col1 AS col1, "
            "table1.col2 AS col2, table1.col3 AS col3 "
            "FROM table1) AS foo LIMIT :param_1 OFFSET "
            ":param_2) AS anon_1 LEFT OUTER JOIN "
            "table2 ON anon_1.col1 = table2.col1",
            {"param_1": 5, "param_2": 10},
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:19,代码来源:test_external_traversal.py

示例12: test_label_anonymize_one

# 需要导入模块: from sqlalchemy.sql import util [as 别名]
# 或者: from sqlalchemy.sql.util import ClauseAdapter [as 别名]
def test_label_anonymize_one(self):
        t1a = t1.alias()
        adapter = sql_util.ClauseAdapter(t1a, anonymize_labels=True)

        expr = select([t1.c.col2]).where(t1.c.col3 == 5).label("expr")
        expr_adapted = adapter.traverse(expr)

        stmt = select([expr, expr_adapted]).order_by(expr, expr_adapted)
        self.assert_compile(
            stmt,
            "SELECT "
            "(SELECT table1.col2 FROM table1 WHERE table1.col3 = :col3_1) "
            "AS expr, "
            "(SELECT table1_1.col2 FROM table1 AS table1_1 "
            "WHERE table1_1.col3 = :col3_2) AS anon_1 "
            "ORDER BY expr, anon_1",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:19,代码来源:test_external_traversal.py

示例13: test_label_anonymize_two

# 需要导入模块: from sqlalchemy.sql import util [as 别名]
# 或者: from sqlalchemy.sql.util import ClauseAdapter [as 别名]
def test_label_anonymize_two(self):
        t1a = t1.alias()
        adapter = sql_util.ClauseAdapter(t1a, anonymize_labels=True)

        expr = select([t1.c.col2]).where(t1.c.col3 == 5).label(None)
        expr_adapted = adapter.traverse(expr)

        stmt = select([expr, expr_adapted]).order_by(expr, expr_adapted)
        self.assert_compile(
            stmt,
            "SELECT "
            "(SELECT table1.col2 FROM table1 WHERE table1.col3 = :col3_1) "
            "AS anon_1, "
            "(SELECT table1_1.col2 FROM table1 AS table1_1 "
            "WHERE table1_1.col3 = :col3_2) AS anon_2 "
            "ORDER BY anon_1, anon_2",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:19,代码来源:test_external_traversal.py

示例14: adapt

# 需要导入模块: from sqlalchemy.sql import util [as 别名]
# 或者: from sqlalchemy.sql.util import ClauseAdapter [as 别名]
def adapt(adapt_with, expression):
    if isinstance(expression.expression, sa.Column):
        cols = get_attrs(adapt_with)
        return getattr(cols, expression.name)
    if not hasattr(adapt_with, 'is_derived_from'):
        adapt_with = sa.inspect(adapt_with).selectable
    return ClauseAdapter(adapt_with).traverse(expression.expression) 
开发者ID:kvesteri,项目名称:sqlalchemy-json-api,代码行数:9,代码来源:utils.py

示例15: test_aggregate_order_by_adapt

# 需要导入模块: from sqlalchemy.sql import util [as 别名]
# 或者: from sqlalchemy.sql.util import ClauseAdapter [as 别名]
def test_aggregate_order_by_adapt(self):
        m = MetaData()
        table = Table("table1", m, Column("a", Integer), Column("b", Integer))
        expr = func.array_agg(aggregate_order_by(table.c.a, table.c.b.desc()))
        stmt = select([expr])

        a1 = table.alias("foo")
        stmt2 = sql_util.ClauseAdapter(a1).traverse(stmt)
        self.assert_compile(
            stmt2,
            "SELECT array_agg(foo.a ORDER BY foo.b DESC) AS array_agg_1 "
            "FROM table1 AS foo",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:15,代码来源:test_compiler.py


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