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


Python expression.ClauseElement方法代码示例

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


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

示例1: _make_simple_select

# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import ClauseElement [as 别名]
def _make_simple_select(cls: Type[T], *args: ClauseElement) -> Select:
        """
        Create a simple ``SELECT * FROM table WHERE <args>`` statement.

        Args:
            *args: The WHERE clauses. If there are many elements, they're joined with AND.

        Returns:
            The SQLAlchemy SELECT statement object.
        """
        if len(args) > 1:
            return cls.t.select().where(and_(*args))
        elif len(args) == 1:
            return cls.t.select().where(args[0])
        else:
            return cls.t.select() 
开发者ID:tulir,项目名称:mautrix-python,代码行数:18,代码来源:base.py

示例2: test_query_return_type

# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import ClauseElement [as 别名]
def test_query_return_type(self, spelldb, sample_points):
        """Test if query() returns the correct type"""

        core = spelldb.spell.get_core(spelldb.dburl)
        engine = core.get_engine()

        source_table, target_table = core.get_tables(
            source_uri=spelldb.spell.source_table,
            target=sample_points,
            engine=engine,
        )
        # Perform the test
        query = spelldb.spell.query(
            source=source_table,
            target=target_table,
            core=core,
            column="WKT",
            pkey="__index_level_0__",
        )
        assert isinstance(query, ClauseElement) 
开发者ID:thinkingmachines,项目名称:geomancer,代码行数:22,代码来源:base_test_spell.py

示例3: test_callout_to_compiler

# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import ClauseElement [as 别名]
def test_callout_to_compiler(self):
        class InsertFromSelect(ClauseElement):
            def __init__(self, table, select):
                self.table = table
                self.select = select

        @compiles(InsertFromSelect)
        def visit_insert_from_select(element, compiler, **kw):
            return "INSERT INTO %s (%s)" % (
                compiler.process(element.table, asfrom=True),
                compiler.process(element.select),
            )

        t1 = table("mytable", column("x"), column("y"), column("z"))
        self.assert_compile(
            InsertFromSelect(t1, select([t1]).where(t1.c.x > 5)),
            "INSERT INTO mytable (SELECT mytable.x, mytable.y, mytable.z "
            "FROM mytable WHERE mytable.x > :x_1)",
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:21,代码来源:test_compiler.py

示例4: compiles

# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import ClauseElement [as 别名]
def compiles(class_, *specs):
    """Register a function as a compiler for a
    given :class:`.ClauseElement` type."""

    def decorate(fn):
        existing = class_.__dict__.get('_compiler_dispatcher', None)
        existing_dispatch = class_.__dict__.get('_compiler_dispatch')
        if not existing:
            existing = _dispatcher()

            if existing_dispatch:
                existing.specs['default'] = existing_dispatch

            # TODO: why is the lambda needed ?
            setattr(class_, '_compiler_dispatch',
                    lambda *arg, **kw: existing(*arg, **kw))
            setattr(class_, '_compiler_dispatcher', existing)

        if specs:
            for s in specs:
                existing.specs[s] = fn

        else:
            existing.specs['default'] = fn
        return fn
    return decorate 
开发者ID:jpush,项目名称:jbox,代码行数:28,代码来源:compiler.py

示例5: deregister

# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import ClauseElement [as 别名]
def deregister(class_):
    """Remove all custom compilers associated with a given
    :class:`.ClauseElement` type."""

    if hasattr(class_, '_compiler_dispatcher'):
        # regenerate default _compiler_dispatch
        visitors._generate_dispatch(class_)
        # remove custom directive
        del class_._compiler_dispatcher 
开发者ID:jpush,项目名称:jbox,代码行数:11,代码来源:compiler.py

示例6: db_create

# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import ClauseElement [as 别名]
def db_create(self, model, defaults=None, **kwargs):
    params = dict((k, v) for k, v in kwargs.items() if not isinstance(v, ClauseElement))
    params.update(defaults or {})
    instance = model(**params)
    self.session.add(instance)
    self.session.flush()
    return instance 
开发者ID:archlinux,项目名称:arch-security-tracker,代码行数:9,代码来源:__init__.py

示例7: _select_all

# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import ClauseElement [as 别名]
def _select_all(cls: Type[T], *args: ClauseElement) -> Iterator[T]:
        """
        Select all rows with given conditions. This is intended to be used by table-specific
        select methods.

        Args:
            *args: The WHERE clauses. If there are many elements, they're joined with AND.

        Yields:
            The objects representing the rows read with :meth:`scan`
        """
        yield from cls._all(cls.db.execute(cls._make_simple_select(*args))) 
开发者ID:tulir,项目名称:mautrix-python,代码行数:14,代码来源:base.py

示例8: _select_one_or_none

# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import ClauseElement [as 别名]
def _select_one_or_none(cls: Type[T], *args: ClauseElement) -> T:
        """
        Select one row with given conditions. If no row is found, return ``None``. This is intended
        to be used by table-specific select methods.

        Args:
            *args: The WHERE clauses. If there are many elements, they're joined with AND.

        Returns:
            The object representing the matched row read with :meth:`scan`, or ``None`` if no rows
            matched.
        """
        return cls._one_or_none(cls.db.execute(cls._make_simple_select(*args))) 
开发者ID:tulir,项目名称:mautrix-python,代码行数:15,代码来源:base.py

示例9: _constraint_to_clause

# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import ClauseElement [as 别名]
def _constraint_to_clause(self, constraint: Constraint) -> ClauseElement:
        return and_(*[column == self.__dict__[name]
                      for name, column in constraint.columns.items()]) 
开发者ID:tulir,项目名称:mautrix-python,代码行数:5,代码来源:base.py

示例10: _edit_identity

# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import ClauseElement [as 别名]
def _edit_identity(self: T) -> ClauseElement:
        """The SQLAlchemy WHERE clause used for editing and deleting individual rows.
        Usually AND of primary keys."""
        return self._constraint_to_clause(self.t.primary_key) 
开发者ID:tulir,项目名称:mautrix-python,代码行数:6,代码来源:base.py

示例11: compiles

# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import ClauseElement [as 别名]
def compiles(class_, *specs):
    """Register a function as a compiler for a
    given :class:`.ClauseElement` type."""

    def decorate(fn):
        # get an existing @compiles handler
        existing = class_.__dict__.get('_compiler_dispatcher', None)

        # get the original handler.  All ClauseElement classes have one
        # of these, but some TypeEngine classes will not.
        existing_dispatch = getattr(class_, '_compiler_dispatch', None)

        if not existing:
            existing = _dispatcher()

            if existing_dispatch:
                def _wrap_existing_dispatch(element, compiler, **kw):
                    try:
                        return existing_dispatch(element, compiler, **kw)
                    except exc.UnsupportedCompilationError:
                        raise exc.CompileError(
                            "%s construct has no default "
                            "compilation handler." % type(element))
                existing.specs['default'] = _wrap_existing_dispatch

            # TODO: why is the lambda needed ?
            setattr(class_, '_compiler_dispatch',
                    lambda *arg, **kw: existing(*arg, **kw))
            setattr(class_, '_compiler_dispatcher', existing)

        if specs:
            for s in specs:
                existing.specs[s] = fn

        else:
            existing.specs['default'] = fn
        return fn
    return decorate 
开发者ID:yfauser,项目名称:planespotter,代码行数:40,代码来源:compiler.py

示例12: __init__

# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import ClauseElement [as 别名]
def __init__(self, name):
        """
        Builds the Executable/ClauseElement that represents the refresh command

        Parameters
        ----------
        name: str, required
            The name of the view to refresh
        """
        self.name = name 
开发者ID:sqlalchemy-redshift,项目名称:sqlalchemy-redshift,代码行数:12,代码来源:commands.py

示例13: get_or_create

# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import ClauseElement [as 别名]
def get_or_create(self, model, **kwargs):
        """ Simple helper to either get an existing record if it exists otherwise create and return a new instance """
        instance = self.session.query(model).filter_by(**kwargs).first()
        if instance:
            return instance
        else:
            params = dict((k, v) for k, v in kwargs.items() if not isinstance(v, ClauseElement))
            instance = model(**params)
            return instance 
开发者ID:epi052,项目名称:recon-pipeline,代码行数:11,代码来源:db_manager.py

示例14: deregister

# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import ClauseElement [as 别名]
def deregister(class_):
    """Remove all custom compilers associated with a given
    :class:`_expression.ClauseElement` type.

    """

    if hasattr(class_, "_compiler_dispatcher"):
        class_._compiler_dispatch = class_._original_compiler_dispatch
        del class_._compiler_dispatcher 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:11,代码来源:compiler.py

示例15: test_unsupported_element_str_visit_name

# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import ClauseElement [as 别名]
def test_unsupported_element_str_visit_name(self):
        from sqlalchemy.sql.expression import ClauseElement

        class SomeElement(ClauseElement):
            __visit_name__ = "some_element"

        assert_raises_message(
            exc.UnsupportedCompilationError,
            r"Compiler <sqlalchemy.sql.compiler.StrSQLCompiler .*"
            r"can't render element of type <class '.*SomeElement'>",
            SomeElement().compile,
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:14,代码来源:test_compiler.py


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