本文整理匯總了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")