本文整理汇总了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
示例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
示例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
示例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
示例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"},
)
示例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()
示例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())
示例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())
示例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
""")
示例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
示例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
示例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])
示例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])
示例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)
示例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