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


Python sql.ColumnElement方法代码示例

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


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

示例1: define_tables

# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import ColumnElement [as 别名]
def define_tables(cls, metadata):
        from sqlalchemy.sql import ColumnElement
        from sqlalchemy.ext.compiler import compiles

        counter = itertools.count()

        class IncDefault(ColumnElement):
            pass

        @compiles(IncDefault)
        def compile_(element, compiler, **kw):
            return str(next(counter))

        Table(
            "t1",
            metadata,
            Column(
                "id", Integer, primary_key=True, test_needs_autoincrement=True
            ),
            Column("data", String(50)),
            Column("insdef", Integer, default=IncDefault()),
            Column("upddef", Integer, onupdate=IncDefault()),
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:25,代码来源:test_returning.py

示例2: test_cache_key_no_method

# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import ColumnElement [as 别名]
def test_cache_key_no_method(self):
        class Foobar1(ClauseElement):
            pass

        class Foobar2(ColumnElement):
            pass

        # the None for cache key will prevent objects
        # which contain these elements from being cached.
        f1 = Foobar1()
        eq_(f1._generate_cache_key(), None)

        f2 = Foobar2()
        eq_(f2._generate_cache_key(), None)

        s1 = select([column("q"), Foobar2()])

        eq_(s1._generate_cache_key(), None) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:20,代码来源:test_compare.py

示例3: test_all_present

# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import ColumnElement [as 别名]
def test_all_present(self):
        need = set(
            cls
            for cls in class_hierarchy(ClauseElement)
            if issubclass(cls, (ColumnElement, Selectable, LambdaElement))
            and (
                "__init__" in cls.__dict__
                or issubclass(cls, AliasedReturnsRows)
            )
            and not issubclass(cls, (Annotated))
            and "orm" not in cls.__module__
            and "compiler" not in cls.__module__
            and "crud" not in cls.__module__
            and "dialects" not in cls.__module__  # TODO: dialects?
        ).difference({ColumnElement, UnaryExpression})

        for fixture in self.fixtures + self.dont_compare_values_fixtures:
            case_a = fixture()
            for elem in case_a:
                for mro in type(elem).__mro__:
                    need.discard(mro)

        is_false(bool(need), "%d Remaining classes: %r" % (len(need), need)) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:25,代码来源:test_compare.py

示例4: get_time_filter

# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import ColumnElement [as 别名]
def get_time_filter(
        self,
        start_dttm: DateTime,
        end_dttm: DateTime,
        time_range_endpoints: Optional[
            Tuple[utils.TimeRangeEndpoint, utils.TimeRangeEndpoint]
        ],
    ) -> ColumnElement:
        col = self.get_sqla_col(label="__time")
        l = []
        if start_dttm:
            l.append(
                col >= text(self.dttm_sql_literal(start_dttm, time_range_endpoints))
            )
        if end_dttm:
            if (
                time_range_endpoints
                and time_range_endpoints[1] == utils.TimeRangeEndpoint.EXCLUSIVE
            ):
                l.append(
                    col < text(self.dttm_sql_literal(end_dttm, time_range_endpoints))
                )
            else:
                l.append(col <= text(self.dttm_sql_literal(end_dttm, None)))
        return and_(*l) 
开发者ID:apache,项目名称:incubator-superset,代码行数:27,代码来源:models.py

示例5: test_get_children_no_method

# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import ColumnElement [as 别名]
def test_get_children_no_method(self):
        class Foobar1(ClauseElement):
            pass

        class Foobar2(ColumnElement):
            pass

        f1 = Foobar1()
        eq_(f1.get_children(), [])

        f2 = Foobar2()
        eq_(f2.get_children(), []) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:14,代码来源:test_compare.py

示例6: test_copy_internals_no_method

# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import ColumnElement [as 别名]
def test_copy_internals_no_method(self):
        class Foobar1(ClauseElement):
            pass

        class Foobar2(ColumnElement):
            pass

        f1 = Foobar1()
        f2 = Foobar2()

        f1._copy_internals()
        f2._copy_internals() 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:14,代码来源:test_compare.py

示例7: test_keyed_targeting_no_label_at_all_two

# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import ColumnElement [as 别名]
def test_keyed_targeting_no_label_at_all_two(self, connection):
        class not_named_max(expression.ColumnElement):
            name = "not_named_max"

        @compiles(not_named_max)
        def visit_max(element, compiler, **kw):
            # we don't add to keymap here; compiler should be doing it
            return "max(a)"

        # assert that there is no "AS max_" or any label of any kind.
        eq_(str(select([not_named_max()])), "SELECT max(a)")

        nnm = not_named_max()
        self._test_keyed_targeting_no_label_at_all(nnm, connection) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:16,代码来源:test_resultset.py

示例8: test_adapt_result_columns

# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import ColumnElement [as 别名]
def test_adapt_result_columns(self, connection, stmt_fn):
        """test adaptation of a CursorResultMetadata to another one.


        This copies the _keymap from one to the other in terms of the
        selected columns of a target selectable.

        This is used by the statement caching process to re-use the
        CursorResultMetadata from the cached statement against the same
        statement sent separately.

        """

        stmt1 = stmt_fn(self)
        stmt2 = stmt_fn(self)

        eq_(stmt1._generate_cache_key(), stmt2._generate_cache_key())

        column_linkage = dict(
            zip(stmt1.selected_columns, stmt2.selected_columns)
        )

        result = connection.execute(stmt1)

        mock_context = Mock(
            compiled=result.context.compiled, invoked_statement=stmt2
        )
        existing_metadata = result._metadata
        adapted_metadata = existing_metadata._adapt_to_context(mock_context)

        eq_(existing_metadata.keys, adapted_metadata.keys)

        for k in existing_metadata._keymap:
            if isinstance(k, ColumnElement) and k in column_linkage:
                other_k = column_linkage[k]
            else:
                other_k = k

            is_(
                existing_metadata._keymap[k], adapted_metadata._keymap[other_k]
            ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:43,代码来源:test_resultset.py

示例9: define_tables

# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import ColumnElement [as 别名]
def define_tables(cls, metadata):
        from sqlalchemy.sql import ColumnElement
        from sqlalchemy.ext.compiler import compiles
        import itertools

        counter = itertools.count(1)

        class IncDefault(ColumnElement):
            pass

        @compiles(IncDefault)
        def compile_(element, compiler, **kw):
            # cache the counter value on the statement
            # itself so the assertsql system gets the same
            # value when it compiles the statement a second time
            stmt = compiler.statement
            if hasattr(stmt, "_counter"):
                return stmt._counter
            else:
                stmt._counter = str(next(counter))
                return stmt._counter

        Table(
            "version_table",
            metadata,
            Column(
                "id", Integer, primary_key=True, test_needs_autoincrement=True
            ),
            Column(
                "version_id",
                Integer,
                nullable=False,
                default=IncDefault(),
                onupdate=IncDefault(),
            ),
            Column("value", String(40), nullable=False),
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:39,代码来源:test_versioning.py

示例10: _get_top_groups

# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import ColumnElement [as 别名]
def _get_top_groups(  # pylint: disable=no-self-use
        self,
        df: pd.DataFrame,
        dimensions: List[str],
        groupby_exprs: "OrderedDict[str, Any]",
    ) -> ColumnElement:
        groups = []
        for _unused, row in df.iterrows():
            group = []
            for dimension in dimensions:
                group.append(groupby_exprs[dimension] == row[dimension])
            groups.append(and_(*group))

        return or_(*groups) 
开发者ID:apache,项目名称:incubator-superset,代码行数:16,代码来源:models.py


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