Python sqlalchemy.sql.true() Examples
The following are 30
code examples of sqlalchemy.sql.true().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
sqlalchemy.sql
, or try the search function
.
Example #1
Source File: hour_slice.py From FlowKit with Mozilla Public License 2.0 | 6 votes |
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()
Example #2
Source File: test_sqlite.py From sqlalchemy with MIT License | 6 votes |
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()
Example #3
Source File: test_operators.py From sqlalchemy with MIT License | 5 votes |
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", )
Example #4
Source File: test_operators.py From sqlalchemy with MIT License | 5 votes |
def test_single_bool_five(self): self.assert_compile(~or_(False), "true")
Example #5
Source File: test_operators.py From sqlalchemy with MIT License | 5 votes |
def test_single_bool_six(self): self.assert_compile(and_(~or_(false())), "true")
Example #6
Source File: test_operators.py From sqlalchemy with MIT License | 5 votes |
def test_five(self): x = column("x") self.assert_compile(and_(true()._ifnone(None), x == 7), "x = :x_1")
Example #7
Source File: test_operators.py From sqlalchemy with MIT License | 5 votes |
def test_six(self): x = column("x") self.assert_compile(or_(true(), x == 7), "true") self.assert_compile(or_(x == 7, true()), "true") self.assert_compile(~or_(x == 7, true()), "false")
Example #8
Source File: test_operators.py From sqlalchemy with MIT License | 5 votes |
def test_six_pt_five(self): x = column("x") self.assert_compile( select([x]).where(or_(x == 7, true())), "SELECT x WHERE true" ) self.assert_compile( select([x]).where(or_(x == 7, true())), "SELECT x WHERE 1 = 1", dialect=default.DefaultDialect(supports_native_boolean=False), )
Example #9
Source File: test_operators.py From sqlalchemy with MIT License | 5 votes |
def test_seven(self): x = column("x") self.assert_compile( and_(true(), x == 7, true(), x == 9), "x = :x_1 AND x = :x_2" )
Example #10
Source File: test_operators.py From sqlalchemy with MIT License | 5 votes |
def test_nine(self): x = column("x") self.assert_compile(and_(x == 7, x == 9, false(), x == 5), "false") self.assert_compile(~and_(x == 7, x == 9, false(), x == 5), "true")
Example #11
Source File: test_operators.py From sqlalchemy with MIT License | 5 votes |
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", )
Example #12
Source File: nfvo_db_plugin.py From tacker with Apache License 2.0 | 5 votes |
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()
Example #13
Source File: test_operators.py From sqlalchemy with MIT License | 5 votes |
def test_is_true_literal(self): c = column("x", Boolean) self.assert_compile(c.is_(True), "x IS true")
Example #14
Source File: test_operators.py From sqlalchemy with MIT License | 5 votes |
def test_and_true_literal_leading(self): self.assert_compile(and_(True, True), "true") self.assert_compile(and_(True, False), "false")
Example #15
Source File: test_operators.py From sqlalchemy with MIT License | 5 votes |
def test_or_false_literal_leading(self): self.assert_compile(or_(False, True), "true") self.assert_compile(or_(False, False), "false")
Example #16
Source File: test_roles.py From sqlalchemy with MIT License | 5 votes |
def test_const_expr_role(self): t = true() is_(expect(roles.ConstExprRole, t), t) f = false() is_(expect(roles.ConstExprRole, f), f) is_instance_of(expect(roles.ConstExprRole, True), True_) is_instance_of(expect(roles.ConstExprRole, False), False_) is_instance_of(expect(roles.ConstExprRole, None), Null)
Example #17
Source File: __init__.py From koschei with GNU General Public License v2.0 | 5 votes |
def _check_untagged_builds(session, collection, package_map, build_infos): """ Check whether some of the builds we have weren't untagged/deleted in the meantime. Only checks last builds of packages. """ for info in build_infos: package = package_map.get(info['package_name']) # info contains the last build for the package that Koji knows if package and util.is_build_newer(info, package.last_build): # The last build (possibly more) we have is newer than last build in Koji. # That means it was untagged or deleted. # Get the last build we have that was not untagged. last_valid_build_query = ( session.db.query(Build) .filter( (Build.package_id == package.id) & (Build.epoch == info['epoch']) & (Build.version == info['version']) & (Build.release == info['release']) ) .order_by(Build.started.desc()) ) last_valid_build = last_valid_build_query.first() if not last_valid_build: # We don't have the build anymore, register it again register_real_builds(session, collection, [(package.id, info)]) # Now, it must find it as we've just inserted it last_valid_build = last_valid_build_query.first() # set all following builds as untagged # last_build pointers get reset by the trigger ( session.db.query(Build) .filter(Build.package_id == package.id) .filter( Build.started > last_valid_build.started if last_valid_build else true() ) .update({'untagged': True}) ) session.log.info("{} is no longer tagged".format(package.last_build))
Example #18
Source File: test_operators.py From sqlalchemy with MIT License | 5 votes |
def test_single_bool_three(self): self.assert_compile(or_(~and_(true())), "false")
Example #19
Source File: bagpipe.py From networking-bgpvpn with Apache License 2.0 | 5 votes |
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())
Example #20
Source File: db_base.py From tacker with Apache License 2.0 | 5 votes |
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
Example #21
Source File: hour_slice.py From FlowKit with Mozilla Public License 2.0 | 5 votes |
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()
Example #22
Source File: test_sqlite.py From sqlalchemy with MIT License | 5 votes |
def test_true_false(self): self.assert_compile(sql.false(), "0") self.assert_compile(sql.true(), "1")
Example #23
Source File: test_compiler.py From sqlalchemy with MIT License | 5 votes |
def test_true_false(self): self.assert_compile(sql.false(), "0") self.assert_compile(sql.true(), "1")
Example #24
Source File: test_compiler.py From sqlalchemy with MIT License | 5 votes |
def test_true_false(self): self.assert_compile(sql.false(), "0") self.assert_compile(sql.true(), "1")
Example #25
Source File: test_operators.py From sqlalchemy with MIT License | 5 votes |
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), )
Example #26
Source File: test_operators.py From sqlalchemy with MIT License | 5 votes |
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), )
Example #27
Source File: test_operators.py From sqlalchemy with MIT License | 5 votes |
def test_eight(self): self.assert_compile( and_(false(), true()), "false", dialect=self._dialect(True) )
Example #28
Source File: test_operators.py From sqlalchemy with MIT License | 5 votes |
def test_nine(self): self.assert_compile( and_(false(), true()), "0 = 1", dialect=self._dialect(False) )
Example #29
Source File: test_operators.py From sqlalchemy with MIT License | 5 votes |
def test_eleven(self): c = column("x", Boolean) self.assert_compile( c.is_(true()), "x IS true", dialect=self._dialect(True) )
Example #30
Source File: test_operators.py From sqlalchemy with MIT License | 5 votes |
def test_single_bool_one(self): self.assert_compile(~and_(true()), "false")