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


Python sqlalchemy.null方法代碼示例

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


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

示例1: __init__

# 需要導入模塊: import sqlalchemy [as 別名]
# 或者: from sqlalchemy import null [as 別名]
def __init__(self, none_as_null=False):
        """Construct a :class:`.JSON` type.

        :param none_as_null: if True, persist the value ``None`` as a
         SQL NULL value, not the JSON encoding of ``null``.   Note that
         when this flag is False, the :func:`.null` construct can still
         be used to persist a NULL value::

             from sqlalchemy import null
             conn.execute(table.insert(), data=null())

         .. versionchanged:: 0.9.8 - Added ``none_as_null``, and :func:`.null`
            is now supported in order to persist a NULL value.

         """
        self.none_as_null = none_as_null 
開發者ID:jpush,項目名稱:jbox,代碼行數:18,代碼來源:json.py

示例2: __init__

# 需要導入模塊: import sqlalchemy [as 別名]
# 或者: from sqlalchemy import null [as 別名]
def __init__(self, none_as_null=False):
        """Construct a :class:`.types.JSON` type.

        :param none_as_null=False: if True, persist the value ``None`` as a
         SQL NULL value, not the JSON encoding of ``null``.   Note that
         when this flag is False, the :func:`.null` construct can still
         be used to persist a NULL value::

             from sqlalchemy import null
             conn.execute(table.insert(), data=null())

         .. note::

              :paramref:`.JSON.none_as_null` does **not** apply to the
              values passed to :paramref:`.Column.default` and
              :paramref:`.Column.server_default`; a value of ``None`` passed for
              these parameters means "no default present".

         .. seealso::

              :attr:`.types.JSON.NULL`

         """
        self.none_as_null = none_as_null 
開發者ID:yfauser,項目名稱:planespotter,代碼行數:26,代碼來源:sqltypes.py

示例3: _get_alarm_definition

# 需要導入模塊: import sqlalchemy [as 別名]
# 或者: from sqlalchemy import null [as 別名]
def _get_alarm_definition(self, conn, tenant_id, _id):
        ad = self.ad_s
        query = (self.base_query
                 .select_from(self.base_query_from)
                 .where(ad.c.tenant_id == bindparam('b_tenant_id'))
                 .where(ad.c.id == bindparam('b_id'))
                 .where(ad.c.deleted_at == null()))

        row = conn.execute(query,
                           b_tenant_id=tenant_id,
                           b_id=_id).fetchone()

        if row is not None:
            return dict(row)
        else:
            raise exceptions.DoesNotExistException 
開發者ID:openstack,項目名稱:monasca-api,代碼行數:18,代碼來源:alarm_definitions_repository.py

示例4: __init__

# 需要導入模塊: import sqlalchemy [as 別名]
# 或者: from sqlalchemy import null [as 別名]
def __init__(self, none_as_null=False):
        """Construct a :class:`_types.JSON` type.

        :param none_as_null=False: if True, persist the value ``None`` as a
         SQL NULL value, not the JSON encoding of ``null``.   Note that
         when this flag is False, the :func:`.null` construct can still
         be used to persist a NULL value::

             from sqlalchemy import null
             conn.execute(table.insert(), data=null())

         .. note::

              :paramref:`_types.JSON.none_as_null` does **not** apply to the
              values passed to :paramref:`_schema.Column.default` and
              :paramref:`_schema.Column.server_default`; a value of ``None``
              passed for these parameters means "no default present".

         .. seealso::

              :attr:`.types.JSON.NULL`

         """
        self.none_as_null = none_as_null 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:26,代碼來源:sqltypes.py

示例5: test_do_update_set_clause_literal

# 需要導入模塊: import sqlalchemy [as 別名]
# 或者: from sqlalchemy import null [as 別名]
def test_do_update_set_clause_literal(self):
        i = insert(self.table_with_metadata).values(myid=1, name="foo")
        i = i.on_conflict_do_update(
            index_elements=["myid"],
            set_=OrderedDict(
                [("name", "I'm a name"), ("description", null())]
            ),
        )
        self.assert_compile(
            i,
            "INSERT INTO mytable (myid, name) VALUES "
            "(%(myid)s, %(name)s) ON CONFLICT (myid) "
            "DO UPDATE SET name = %(param_1)s, "
            "description = NULL",
            {"myid": 1, "name": "foo", "param_1": "I'm a name"},
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:18,代碼來源:test_compiler.py

示例6: test_filter_by

# 需要導入模塊: import sqlalchemy [as 別名]
# 或者: from sqlalchemy import null [as 別名]
def test_filter_by(self):
        User, Address = self.classes.User, self.classes.Address

        sess = create_session()
        user = sess.query(User).get(8)
        assert [Address(id=2), Address(id=3), Address(id=4)] == sess.query(
            Address
        ).filter_by(user=user).all()

        # many to one generates IS NULL
        assert [] == sess.query(Address).filter_by(user=None).all()
        assert [] == sess.query(Address).filter_by(user=null()).all()

        # one to many generates WHERE NOT EXISTS
        assert [User(name="chuck")] == sess.query(User).filter_by(
            addresses=None
        ).all()
        assert [User(name="chuck")] == sess.query(User).filter_by(
            addresses=null()
        ).all() 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:22,代碼來源:test_query.py

示例7: _is_null

# 需要導入模塊: import sqlalchemy [as 別名]
# 或者: from sqlalchemy import null [as 別名]
def _is_null(t, expr):
    arg = t.translate(expr.op().args[0])
    return arg.is_(sa.null()) 
開發者ID:ibis-project,項目名稱:ibis,代碼行數:5,代碼來源:alchemy.py

示例8: _not_null

# 需要導入模塊: import sqlalchemy [as 別名]
# 或者: from sqlalchemy import null [as 別名]
def _not_null(t, expr):
    arg = t.translate(expr.op().args[0])
    return arg.isnot(sa.null()) 
開發者ID:ibis-project,項目名稱:ibis,代碼行數:5,代碼來源:alchemy.py

示例9: upgrade

# 需要導入模塊: import sqlalchemy [as 別名]
# 或者: from sqlalchemy import null [as 別名]
def upgrade():
    op.alter_column(
        'services',
        'consent_to_research',
        existing_type=sa.BOOLEAN(),
        nullable=True,
        server_default=sa.null(),
    )
    op.alter_column(
        'services_history',
        'consent_to_research',
        existing_type=sa.BOOLEAN(),
        nullable=True,
        server_default=sa.null(),
    )
    op.execute("""
        UPDATE
            services
        SET
            consent_to_research = null
    """)
    op.execute("""
        UPDATE
            services_history
        SET
            consent_to_research = null
    """) 
開發者ID:alphagov,項目名稱:notifications-api,代碼行數:29,代碼來源:0277_consent_to_research_null.py

示例10: __init__

# 需要導入模塊: import sqlalchemy [as 別名]
# 或者: from sqlalchemy import null [as 別名]
def __init__(self, none_as_null=False, astext_type=None):
        """Construct a :class:`.JSON` type.

        :param none_as_null: if True, persist the value ``None`` as a
         SQL NULL value, not the JSON encoding of ``null``.   Note that
         when this flag is False, the :func:`.null` construct can still
         be used to persist a NULL value::

             from sqlalchemy import null
             conn.execute(table.insert(), data=null())

         .. versionchanged:: 0.9.8 - Added ``none_as_null``, and :func:`.null`
            is now supported in order to persist a NULL value.

         .. seealso::

              :attr:`.JSON.NULL`

        :param astext_type: the type to use for the
         :attr:`.JSON.Comparator.astext`
         accessor on indexed attributes.  Defaults to :class:`.types.Text`.

         .. versionadded:: 1.1

         """
        super(JSON, self).__init__(none_as_null=none_as_null)
        if astext_type is not None:
            self.astext_type = astext_type 
開發者ID:yfauser,項目名稱:planespotter,代碼行數:30,代碼來源:json.py

示例11: __init__

# 需要導入模塊: import sqlalchemy [as 別名]
# 或者: from sqlalchemy import null [as 別名]
def __init__(self, none_as_null=False, astext_type=None):
        """Construct a :class:`_types.JSON` type.

        :param none_as_null: if True, persist the value ``None`` as a
         SQL NULL value, not the JSON encoding of ``null``.   Note that
         when this flag is False, the :func:`.null` construct can still
         be used to persist a NULL value::

             from sqlalchemy import null
             conn.execute(table.insert(), data=null())

         .. versionchanged:: 0.9.8 - Added ``none_as_null``, and :func:`.null`
            is now supported in order to persist a NULL value.

         .. seealso::

              :attr:`_types.JSON.NULL`

        :param astext_type: the type to use for the
         :attr:`.JSON.Comparator.astext`
         accessor on indexed attributes.  Defaults to :class:`_types.Text`.

         .. versionadded:: 1.1

         """
        super(JSON, self).__init__(none_as_null=none_as_null)
        if astext_type is not None:
            self.astext_type = astext_type 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:30,代碼來源:json.py

示例12: _assert_column_is_NULL

# 需要導入模塊: import sqlalchemy [as 別名]
# 或者: from sqlalchemy import null [as 別名]
def _assert_column_is_NULL(self, conn, column="data"):
        col = self.tables.data_table.c[column]
        data = conn.execute(select([col]).where(col.is_(null()))).fetchall()
        eq_([d for d, in data], [None]) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:6,代碼來源:test_types.py

示例13: _assert_column_is_JSON_NULL

# 需要導入模塊: import sqlalchemy [as 別名]
# 或者: from sqlalchemy import null [as 別名]
def _assert_column_is_JSON_NULL(self, conn, column="data"):
        col = self.tables.data_table.c[column]
        data = conn.execute(
            select([col]).where(cast(col, String) == "null")
        ).fetchall()
        eq_([d for d, in data], [None]) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:8,代碼來源:test_types.py

示例14: _test_insert_nulls

# 需要導入模塊: import sqlalchemy [as 別名]
# 或者: from sqlalchemy import null [as 別名]
def _test_insert_nulls(self, engine):
        with engine.connect() as conn:
            conn.execute(
                self.tables.data_table.insert(), {"name": "r1", "data": null()}
            )
            self._assert_data([None], conn) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:8,代碼來源:test_types.py

示例15: test_alias_union

# 需要導入模塊: import sqlalchemy [as 別名]
# 或者: from sqlalchemy import null [as 別名]
def test_alias_union(self):

        # same as testunion, except its an alias of the union

        u = (
            select(
                [
                    table1.c.col1,
                    table1.c.col2,
                    table1.c.col3,
                    table1.c.colx,
                    null().label("coly"),
                ]
            )
            .union(
                select(
                    [
                        table2.c.col1,
                        table2.c.col2,
                        table2.c.col3,
                        null().label("colx"),
                        table2.c.coly,
                    ]
                )
            )
            .alias("analias")
        )
        s1 = table1.select(use_labels=True).subquery()
        s2 = table2.select(use_labels=True).subquery()
        assert u.corresponding_column(s1.c.table1_col2) is u.c.col2
        assert u.corresponding_column(s2.c.table2_col2) is u.c.col2
        assert u.corresponding_column(s2.c.table2_coly) is u.c.coly
        assert s2.corresponding_column(u.c.coly) is s2.c.table2_coly 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:35,代碼來源:test_selectable.py


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