當前位置: 首頁>>代碼示例>>Python>>正文


Python sql.null方法代碼示例

本文整理匯總了Python中sqlalchemy.sql.null方法的典型用法代碼示例。如果您正苦於以下問題:Python sql.null方法的具體用法?Python sql.null怎麽用?Python sql.null使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sqlalchemy.sql的用法示例。


在下文中一共展示了sql.null方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _serialize_and_update_indexes

# 需要導入模塊: from sqlalchemy import sql [as 別名]
# 或者: from sqlalchemy.sql import null [as 別名]
def _serialize_and_update_indexes(self,obj,collection,d,for_update = False):

        pk_type = self._index_fields[collection]['pk']['type']

        for index_field,index_params in self._index_fields[collection].items():
            try:
                if for_update:
                    value = obj[index_field]
                else:
                    value = get_value(obj,index_field)
                if value is None:
                    if not index_params['field'].nullable:
                        raise ValueError("Value for %s is `None`, but this is a mandatory field!" % index_field)
                    d[index_params['column']] = null()
                else:
                    d[index_params['column']] = expression.cast(value,index_params['type'])
            except KeyError:
                if for_update:
                    continue
                if index_params['field'].default is not None:
                    d[index_params['column']] = index_params['field'].default
                elif not index_params['field'].nullable:
                    raise ValueError("No value for %s given, but this is a mandatory field!" % index_field)
                else:
                    d[index_params['column']] = null() 
開發者ID:adewes,項目名稱:blitzdb,代碼行數:27,代碼來源:backend.py

示例2: _sql_crit

# 需要導入模塊: from sqlalchemy import sql [as 別名]
# 或者: from sqlalchemy.sql import null [as 別名]
def _sql_crit(expression, value):
    """Produce an equality expression against the given value.

    This takes into account a value that is actually a collection
    of values, as well as a value of None or collection that contains
    None.

    """

    values = utils.to_list(value, default=(None, ))
    if len(values) == 1:
        if values[0] is None:
            return expression == sql.null()
        else:
            return expression == values[0]
    elif _none_set.intersection(values):
        return sql.or_(
            expression == sql.null(),
            _sql_crit(expression, set(values).difference(_none_set))
        )
    else:
        return expression.in_(values) 
開發者ID:openstack,項目名稱:oslo.db,代碼行數:24,代碼來源:update_match.py

示例3: _get_replica_schedules_filter

# 需要導入模塊: from sqlalchemy import sql [as 別名]
# 或者: from sqlalchemy.sql import null [as 別名]
def _get_replica_schedules_filter(context, replica_id=None,
                                  schedule_id=None, expired=True):
    now = timeutils.utcnow()
    q = _soft_delete_aware_query(context, models.ReplicaSchedule)
    q = q.join(models.Replica)
    sched_filter = q.filter()
    if is_user_context(context):
        sched_filter = sched_filter.filter(
            models.Replica.project_id == context.tenant)

    if replica_id:
        sched_filter = sched_filter.filter(
            models.Replica.id == replica_id)
    if schedule_id:
        sched_filter = sched_filter.filter(
            models.ReplicaSchedule.id == schedule_id)
    if not expired:
        sched_filter = sched_filter.filter(
            or_(models.ReplicaSchedule.expiration_date == null(),
                models.ReplicaSchedule.expiration_date > now))
    return sched_filter 
開發者ID:cloudbase,項目名稱:coriolis,代碼行數:23,代碼來源:api.py

示例4: auth

# 需要導入模塊: from sqlalchemy import sql [as 別名]
# 或者: from sqlalchemy.sql import null [as 別名]
def auth():
    class FakeAuthentication(AuthenticationBase):
        def get_request_credentials(self):
            return flask.request.args.get("user_id")

    class UserAuthorization(
        AuthorizeModifyMixin, HasCredentialsAuthorizationBase
    ):
        def filter_query(self, query, view):
            return query.filter(
                (view.model.owner_id == self.get_request_credentials())
                | (view.model.owner_id == sql.null())
            )

        def authorize_create_item(self, item):
            super().authorize_create_item(item)

            if item.name == "Updated":
                raise ApiError(403, {"code": "invalid_name"})

        def authorize_modify_item(self, item, action):
            if item.owner_id != self.get_request_credentials():
                raise ApiError(403, {"code": "invalid_user"})

    authorization = UserAuthorization()
    authorization.authorize_modify_item = Mock(
        wraps=authorization.authorize_modify_item, autospec=True
    )

    class BearerWithFallbackAuthentication(HeaderAuthentication):
        credentials_arg = "secret"

    return {
        "authentication": FakeAuthentication(),
        "authorization": authorization,
        "bearer_with_fallback_authentication": (
            BearerWithFallbackAuthentication()
        ),
    } 
開發者ID:4Catalyzer,項目名稱:flask-resty,代碼行數:41,代碼來源:test_auth.py

示例5: test_bind_serialize_None

# 需要導入模塊: from sqlalchemy import sql [as 別名]
# 或者: from sqlalchemy.sql import null [as 別名]
def test_bind_serialize_None(self):
        proc = self.test_table.c.test_column.type._cached_bind_processor(
            self.dialect
        )
        eq_(proc(None), "null") 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:7,代碼來源:test_types.py

示例6: test_bind_serialize_none_as_null

# 需要導入模塊: from sqlalchemy import sql [as 別名]
# 或者: from sqlalchemy.sql import null [as 別名]
def test_bind_serialize_none_as_null(self):
        proc = JSON(none_as_null=True)._cached_bind_processor(self.dialect)
        eq_(proc(None), None)
        eq_(proc(null()), None) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:6,代碼來源:test_types.py

示例7: test_bind_serialize_null

# 需要導入模塊: from sqlalchemy import sql [as 別名]
# 或者: from sqlalchemy.sql import null [as 別名]
def test_bind_serialize_null(self):
        proc = self.test_table.c.test_column.type._cached_bind_processor(
            self.dialect
        )
        eq_(proc(null()), None) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:7,代碼來源:test_types.py

示例8: test_result_deserialize_null

# 需要導入模塊: from sqlalchemy import sql [as 別名]
# 或者: from sqlalchemy.sql import null [as 別名]
def test_result_deserialize_null(self):
        proc = self.test_table.c.test_column.type._cached_result_processor(
            self.dialect, None
        )
        eq_(proc("null"), None) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:7,代碼來源:test_types.py

示例9: test_fourteen

# 需要導入模塊: from sqlalchemy import sql [as 別名]
# 或者: from sqlalchemy.sql import null [as 別名]
def test_fourteen(self):
        x = column("x")
        self.assert_compile(
            select([x]).where(~null()), "SELECT x WHERE NOT NULL"
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:7,代碼來源:test_operators.py

示例10: test_constant_render_distinct

# 需要導入模塊: from sqlalchemy import sql [as 別名]
# 或者: from sqlalchemy.sql import null [as 別名]
def test_constant_render_distinct(self):
        self.assert_compile(
            select([null(), null()]), "SELECT NULL AS anon_1, NULL AS anon__1"
        )
        self.assert_compile(
            select([true(), true()]), "SELECT true AS anon_1, true AS anon__1"
        )
        self.assert_compile(
            select([false(), false()]),
            "SELECT false AS anon_1, false AS anon__1",
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:13,代碼來源:test_operators.py

示例11: test_constant_render_distinct_use_labels

# 需要導入模塊: from sqlalchemy import sql [as 別名]
# 或者: from sqlalchemy.sql import null [as 別名]
def test_constant_render_distinct_use_labels(self):
        self.assert_compile(
            select([null(), null()]).apply_labels(),
            "SELECT NULL AS anon_1, NULL AS anon__1",
        )
        self.assert_compile(
            select([true(), true()]).apply_labels(),
            "SELECT true AS anon_1, true AS anon__1",
        )
        self.assert_compile(
            select([false(), false()]).apply_labels(),
            "SELECT false AS anon_1, false AS anon__1",
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:15,代碼來源:test_operators.py

示例12: test_is_eq_precedence_flat

# 需要導入模塊: from sqlalchemy import sql [as 別名]
# 或者: from sqlalchemy.sql import null [as 別名]
def test_is_eq_precedence_flat(self):
        self.assert_compile(
            (self.table1.c.name == null())
            != (self.table1.c.description == null()),
            "(mytable.name IS NULL) != (mytable.description IS NULL)",
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:8,代碼來源:test_operators.py

示例13: upgrade

# 需要導入模塊: from sqlalchemy import sql [as 別名]
# 或者: from sqlalchemy.sql import null [as 別名]
def upgrade():
    state_enum = sa.Enum(*istate.States.all(), name='node_state')
    state_enum.create(op.get_bind())

    op.add_column('nodes', sa.Column('version_id', sa.String(36),
                                     server_default=''))
    op.add_column('nodes', sa.Column('state', state_enum,
                                     nullable=False,
                                     default=istate.States.finished,
                                     server_default=istate.States.finished))
    # correct the state: finished -> error if Node.error is not null
    stmt = Node.update().where(Node.c.error != sql.null()).values(
        {'state': op.inline_literal(istate.States.error)})
    op.execute(stmt) 
開發者ID:openstack,項目名稱:ironic-inspector,代碼行數:16,代碼來源:d2e48801c8ef_introducing_node_state_attribute.py

示例14: _serialize_and_update_relations

# 需要導入模塊: from sqlalchemy import sql [as 別名]
# 或者: from sqlalchemy.sql import null [as 別名]
def _serialize_and_update_relations(self,obj,collection,d,deletes,inserts,autosave_dependent = True,for_update = False, save_cache=None):

        pk_type = self._index_fields[collection]['pk']['type']

        for related_field,relation_params in self._related_fields[collection].items():

            #we skip back-references...
            if relation_params.get('is_backref',None):
                continue

            try:
                if for_update:
                    value = obj[related_field]
                else:
                    value = get_value(obj,related_field)
                if isinstance(relation_params['field'],ManyToManyField):
                    if isinstance(value,ManyToManyProxy):
                        continue
                    relationship_table = self._relationship_tables[collection][related_field]
                    deletes.append(relationship_table.delete().where(relationship_table.c[relation_params['pk_field_name']] == expression.cast(obj['pk'],pk_type)))
                    for element in value:
                        if not isinstance(element,Document):
                            raise AttributeError("ManyToMany field %s contains an invalid value!" % related_field)
                        if autosave_dependent and element.pk is None:
                            self.save(element, save_cache=save_cache)
                        if element.pk is None:
                            raise AttributeError("Related document in field %s has no primary key!" % related_field)
                        ed = {
                            relation_params['pk_field_name'] : obj['pk'],
                            relation_params['related_pk_field_name'] : element.pk,
                        }
                        inserts.append(relationship_table.insert().values(**ed))
                elif isinstance(relation_params['field'],ForeignKeyField):
                    if value is None:
                        if not relation_params['field'].nullable:
                            raise AttributeError("Field %s cannot be None!" % related_field)
                        d[relation_params['column']] = null()
                    elif not isinstance(value,Document):
                        raise AttributeError("Field %s must be a document!" % related_field)
                    else:
                        if autosave_dependent and value.pk is None:
                            self.save(value, save_cache=save_cache)
                        if value.pk is None:
                            raise AttributeError("Related document in field %s has no primary key!" % related_field)
                        d[relation_params['column']] = expression.cast(value.pk,relation_params['type'])

            except KeyError:
                if for_update:
                    continue
                if isinstance(relation_params['field'],ForeignKeyField):
                    if not relation_params['field'].nullable:
                        raise ValueError("No value for %s given, but this is a mandatory field!" % relation_params['key'])
                    d[relation_params['column']] = null() 
開發者ID:adewes,項目名稱:blitzdb,代碼行數:55,代碼來源:backend.py


注:本文中的sqlalchemy.sql.null方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。