本文整理汇总了Python中sqlalchemy.sql.true方法的典型用法代码示例。如果您正苦于以下问题:Python sql.true方法的具体用法?Python sql.true怎么用?Python sql.true使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.sql
的用法示例。
在下文中一共展示了sql.true方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: filter_timestamp_column
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import true [as 别名]
def filter_timestamp_column(self, ts_col, cmp_op: callable) -> ColumnElement:
"""
Filter timestamp column by comparing to this hour-of-day using the given
comparison operator.
Note that for the class `MissingHourAndMinutesTimestamp` this always
returns TRUE, since a missing timestamp imposes no constraint.
Parameters
----------
ts_col : sqlalchemy column
The timestamp column to filter.
cmp_op : callable
Comparison operator to use. For example: `operator.lt`, `operator.ge`.
Returns
-------
sqlalchemy.sql.elements.True_
"""
return true()
示例2: test_extra_reserved_words
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import true [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()
示例3: get_network_ports
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import true [as 别名]
def get_network_ports(context, network_id):
# NOTE(tmorin): currents callers don't look at detailed results
# but only test if at least one result exist => can be optimized
# by returning a count, rather than all port information
return (context.session.query(models_v2.Port).
filter(models_v2.Port.network_id == network_id,
models_v2.Port.admin_state_up == sql.true()).all())
示例4: _get_default_vim
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import true [as 别名]
def _get_default_vim(self, context):
query = self._model_query(context, nfvo_db.Vim)
return query.filter(
nfvo_db.Vim.tenant_id == context.tenant_id).filter(
nfvo_db.Vim.is_default == sql.true()).one()
示例5: _model_query
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import true [as 别名]
def _model_query(self, context, model):
query = context.session.query(model)
# define basic filter condition for model query
# NOTE(jkoelker) non-admin queries are scoped to their tenant_id
# NOTE(salvatore-orlando): unless the model allows for shared objects
query_filter = None
if not context.is_admin and hasattr(model, 'tenant_id'):
if hasattr(model, 'shared'):
query_filter = ((model.tenant_id == context.tenant_id) |
(model.shared == sql.true()))
else:
query_filter = (model.tenant_id == context.tenant_id)
# Execute query hooks registered from mixins and plugins
model_hooks = self._model_query_hooks.get(model, {})
for _name, hooks in model_hooks.items():
query_hook = hooks.get('query')
if isinstance(query_hook, six.string_types):
query_hook = getattr(self, query_hook, None)
if query_hook:
query = query_hook(context, model, query)
filter_hook = hooks.get('filter')
if isinstance(filter_hook, six.string_types):
filter_hook = getattr(self, filter_hook, None)
if filter_hook:
query_filter = filter_hook(context, model, query_filter)
# NOTE(salvatore-orlando): 'if query_filter' will try to evaluate the
# condition, raising an exception
if query_filter is not None:
query = query.filter(query_filter)
# Don't list the deleted entries
if hasattr(model, 'deleted_at'):
query = query.filter_by(deleted_at=datetime.min)
return query
示例6: filter_timestamp_column_by_day_of_week
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import true [as 别名]
def filter_timestamp_column_by_day_of_week(
self, ts_col: InstrumentedAttribute
) -> ColumnElement:
"""
Returns an expression equivalent to TRUE (because no additional
filtering is needed to limit the day of the week).
Parameters
----------
ts_col : sqlalchemy.orm.attributes.InstrumentedAttribute
The timestamp column to filter. Note that this input argument
is ignored for the DayPeriod class because it requires no
additional filtering to limit the day of the week.
"""
return true()
示例7: test_true_false
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import true [as 别名]
def test_true_false(self):
self.assert_compile(sql.false(), "0")
self.assert_compile(sql.true(), "1")
示例8: test_seven_a
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import true [as 别名]
def test_seven_a(self):
t1 = table("t1", column("a"))
t2 = table("t2", column("b"))
self.assert_compile(
join(t1, t2, onclause=true()),
"t1 JOIN t2 ON 1 = 1",
dialect=self._dialect(False),
)
示例9: test_seven_c
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import true [as 别名]
def test_seven_c(self):
t1 = table("t1", column("a"))
t2 = table("t2", column("b"))
self.assert_compile(
join(t1, t2, onclause=true()),
"t1 JOIN t2 ON true",
dialect=self._dialect(True),
)
示例10: test_eight
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import true [as 别名]
def test_eight(self):
self.assert_compile(
and_(false(), true()), "false", dialect=self._dialect(True)
)
示例11: test_nine
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import true [as 别名]
def test_nine(self):
self.assert_compile(
and_(false(), true()), "0 = 1", dialect=self._dialect(False)
)
示例12: test_eleven
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import true [as 别名]
def test_eleven(self):
c = column("x", Boolean)
self.assert_compile(
c.is_(true()), "x IS true", dialect=self._dialect(True)
)
示例13: test_single_bool_one
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import true [as 别名]
def test_single_bool_one(self):
self.assert_compile(~and_(true()), "false")
示例14: test_single_bool_three
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import true [as 别名]
def test_single_bool_three(self):
self.assert_compile(or_(~and_(true())), "false")
示例15: test_single_bool_four
# 需要导入模块: from sqlalchemy import sql [as 别名]
# 或者: from sqlalchemy.sql import true [as 别名]
def test_single_bool_four(self):
self.assert_compile(~or_(false()), "true")