當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。