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


Python sql.false方法代码示例

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


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

示例1: filter

# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import false [as 别名]
def filter(self, qs, value):
        if value in EMPTY_VALUES:
            return qs

        y_column = getattr(self.model, value['y_column'])

        if value['y_func'] == 'count':
            y_func = func.count(y_column)
        elif value['y_func'] == 'sum':
            y_func = func.sum(y_column)
        elif value['y_func'] == 'min':
            y_func = func.min(y_column)
        elif value['y_func'] == 'max':
            y_func = func.max(y_column)
        elif value['y_func'] == 'avg':
            y_func = func.avg(y_column)
        else:
            return qs.filter(sql.false())

        qs = qs.session.query(y_func).one()

        return qs 
开发者ID:jet-admin,项目名称:jet-bridge,代码行数:24,代码来源:model_aggregate.py

示例2: filter

# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import false [as 别名]
def filter(self, qs, value):
        if value in EMPTY_VALUES:
            return qs

        if len(value) < 2:
            return qs.filter(sql.false())

        ordering = value.split(',')

        def map_field(name):
            descending = False
            if name.startswith('-'):
                name = name[1:]
                descending = True
            field = getattr(self.model, name)
            if descending:
                field = desc(field)
            return field

        if ordering:
            qs = qs.order_by(*map(lambda x: map_field(x), ordering))

        return qs 
开发者ID:jet-admin,项目名称:jet-bridge,代码行数:25,代码来源:order_by.py

示例3: test_extra_reserved_words

# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import false [as 别名]
def test_extra_reserved_words(self):
        """Tests reserved words in identifiers.

        'true', 'false', and 'column' are undocumented reserved words
        when used as column identifiers (as of 3.5.1).  Covering them
        here to ensure they remain in place if the dialect's
        reserved_words set is updated in the future. """

        meta = MetaData(testing.db)
        t = Table(
            "reserved",
            meta,
            Column("safe", Integer),
            Column("true", Integer),
            Column("false", Integer),
            Column("column", Integer),
            Column("exists", Integer),
        )
        try:
            meta.create_all()
            t.insert().execute(safe=1)
            list(t.select().execute())
        finally:
            meta.drop_all() 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:26,代码来源:test_sqlite.py

示例4: user_packages

# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import false [as 别名]
def user_packages(username):
    """
    Displays packages for the current user. What it means is defined by plugins.
    In Fedora, pagure plugin is used, which queries pagure for packages maintained by
    the user.
    """
    names = []
    try:
        results = plugin.dispatch_event('get_user_packages',
                                        session,
                                        username=username)
        for result in results:
            if result:
                names += result
    except Exception:
        flash_nak("Error retrieving user's packages")
        session.log.exception("Error retrieving user's packages")

    def query_fn(query):
        return query.filter(BasePackage.name.in_(names) if names else false())

    return package_view("user-packages.html", query_fn, username=username) 
开发者ID:fedora-infra,项目名称:koschei,代码行数:24,代码来源:views.py

示例5: _get_path_nodes_by_filter

# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import false [as 别名]
def _get_path_nodes_by_filter(self, filters=None):
        qry = self.admin_context.session.query(PathNode)
        if filters:
            for key, value in filters.items():
                column = getattr(PathNode, key, None)
                if column:
                    if not value:
                        qry = qry.filter(sql.false())
                    else:
                        qry = qry.filter(column == value)
        return qry 
开发者ID:openstack,项目名称:networking-sfc,代码行数:13,代码来源:db.py

示例6: _get_port_details_by_filter

# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import false [as 别名]
def _get_port_details_by_filter(self, filters=None):
        qry = self.admin_context.session.query(PortPairDetail)
        if filters:
            for key, value in filters.items():
                column = getattr(PortPairDetail, key, None)
                if column:
                    if not value:
                        qry = qry.filter(sql.false())
                    else:
                        qry = qry.filter(column == value)
        return qry 
开发者ID:openstack,项目名称:networking-sfc,代码行数:13,代码来源:db.py

示例7: get_model_segment_filter

# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import false [as 别名]
def get_model_segment_filter(request, Model):
    mapper = inspect(Model)
    primary_key = mapper.primary_key[0].name

    class ModelSegmentFilter(CharFilter):
        def filter(self, qs, value):
            value = self.clean_value(value)
            if value in EMPTY_VALUES:
                return qs

            body = self.handler.data

            if not isinstance(body, dict):
                return qs.filter(sql.false())

            items = list(filter(lambda x: x.get('name') == value, body.get('segments', [])))

            if len(items) == 0:
                return qs.filter(sql.false())

            query = items[0].get('query')

            serializer = SqlSerializer(data={'query': query}, context={'request': request})
            serializer.is_valid(raise_exception=True)
            result = serializer.execute()
            columns = list(result['columns'])
            rows = result['data']

            if len(columns) == 0 or len(rows) == 0:
                return qs.filter(sql.false())

            ids = list(map(lambda x: list(x)[0], rows))

            return qs.filter(getattr(Model, primary_key).in_(ids))

    return ModelSegmentFilter 
开发者ID:jet-admin,项目名称:jet-bridge,代码行数:38,代码来源:model_segment.py

示例8: filter

# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import false [as 别名]
def filter(self, qs, value):
        if value in EMPTY_VALUES:
            return qs

        x_column = getattr(self.model, value['x_column'])
        y_column = getattr(self.model, value['y_column'])

        if value['y_func'] == 'count':
            y_func = func.count(y_column)
        elif value['y_func'] == 'sum':
            y_func = func.sum(y_column)
        elif value['y_func'] == 'min':
            y_func = func.min(y_column)
        elif value['y_func'] == 'max':
            y_func = func.max(y_column)
        elif value['y_func'] == 'avg':
            y_func = func.avg(y_column)
        else:
            return qs.filter(sql.false())

        if value['x_lookup'] and value['x_lookup'] in ['date']:
            x_lookup = getattr(func, value['x_lookup'])
            x_func = x_lookup(x_column)
        else:
            x_func = x_column

        qs = qs.session.query(x_func.label('group'), y_func.label('y_func')).group_by('group').order_by('group').all()

        return qs 
开发者ID:jet-admin,项目名称:jet-bridge,代码行数:31,代码来源:model_group.py

示例9: test_render_server_default_native_boolean

# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import false [as 别名]
def test_render_server_default_native_boolean(self):
        c = Column(
            "updated_at", Boolean(), server_default=false(), nullable=False
        )
        result = autogenerate.render._render_column(c, self.autogen_context)
        eq_ignore_whitespace(
            result,
            "sa.Column('updated_at', sa.Boolean(), "
            "server_default=sa.text(!U'false'), "
            "nullable=False)",
        ) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:13,代码来源:test_postgresql.py

示例10: test_render_server_default_non_native_boolean

# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import false [as 别名]
def test_render_server_default_non_native_boolean(self):
        c = Column(
            "updated_at", Boolean(), server_default=false(), nullable=False
        )

        result = autogenerate.render._render_column(c, self.autogen_context)
        eq_ignore_whitespace(
            result,
            "sa.Column('updated_at', sa.Boolean(), "
            "server_default=sa.text(!U'0'), "
            "nullable=False)",
        ) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:14,代码来源:test_autogen_render.py

示例11: get_filter

# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import false [as 别名]
def get_filter(self, view, arg_value):
        if arg_value is None:
            return self.get_default_filter(view)

        if not arg_value and not self._allow_empty:
            return sql.false()

        if not self._separator or self._separator not in arg_value:
            return self.get_element_filter(view, arg_value)

        return sa.or_(
            self.get_element_filter(view, value_raw)
            for value_raw in arg_value.split(self._separator)
        ) 
开发者ID:4Catalyzer,项目名称:flask-resty,代码行数:16,代码来源:filtering.py

示例12: get_element_filter

# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import false [as 别名]
def get_element_filter(self, view, value):
        field = self.get_field(view)

        try:
            value = self.deserialize(field, value)
        except ValidationError as e:
            if self._skip_invalid:
                return sql.false()

            raise ApiError.from_validation_error(
                400, e, self.format_validation_error
            ) from e

        return self.get_filter_clause(view, value) 
开发者ID:4Catalyzer,项目名称:flask-resty,代码行数:16,代码来源:filtering.py

示例13: upgrade

# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import false [as 别名]
def upgrade(active_plugins=None, options=None):
    op.add_column('vims', sa.Column('is_default',
                  sa.Boolean(),
                  server_default=sql.false(),
                  nullable=False)) 
开发者ID:openstack,项目名称:tacker,代码行数:7,代码来源:d4f265e8eb9d_add_default_to_vim.py

示例14: test_boolean_default

# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import false [as 别名]
def test_boolean_default(self):
        t = Table(
            "t",
            self.metadata,
            Column("x", Boolean, server_default=sql.false()),
        )
        t.create(testing.db)
        with testing.db.connect() as conn:
            conn.execute(t.insert())
            conn.execute(t.insert().values(x=True))
            eq_(
                conn.execute(t.select().order_by(t.c.x)).fetchall(),
                [(False,), (True,)],
            ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:16,代码来源:test_sqlite.py

示例15: test_true_false

# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import false [as 别名]
def test_true_false(self):
        self.assert_compile(sql.false(), "0")
        self.assert_compile(sql.true(), "1") 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:5,代码来源:test_sqlite.py


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