Python sqlalchemy.sql.false() Examples
The following are 30
code examples of sqlalchemy.sql.false().
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: views.py From koschei with GNU General Public License v2.0 | 6 votes |
def user_packages(username): """ Displays packages for the current user. What it means is defined by plugins. In Fedora, pagure plugin is used, which queries pagure for packages maintained by the user. """ names = [] try: results = plugin.dispatch_event('get_user_packages', session, username=username) for result in results: if result: names += result except Exception: flash_nak("Error retrieving user's packages") session.log.exception("Error retrieving user's packages") def query_fn(query): return query.filter(BasePackage.name.in_(names) if names else false()) return package_view("user-packages.html", query_fn, username=username)
Example #2
Source File: model_aggregate.py From jet-bridge with MIT License | 6 votes |
def filter(self, qs, value): if value in EMPTY_VALUES: return qs y_column = getattr(self.model, value['y_column']) if value['y_func'] == 'count': y_func = func.count(y_column) elif value['y_func'] == 'sum': y_func = func.sum(y_column) elif value['y_func'] == 'min': y_func = func.min(y_column) elif value['y_func'] == 'max': y_func = func.max(y_column) elif value['y_func'] == 'avg': y_func = func.avg(y_column) else: return qs.filter(sql.false()) qs = qs.session.query(y_func).one() return qs
Example #3
Source File: order_by.py From jet-bridge with MIT License | 6 votes |
def filter(self, qs, value): if value in EMPTY_VALUES: return qs if len(value) < 2: return qs.filter(sql.false()) ordering = value.split(',') def map_field(name): descending = False if name.startswith('-'): name = name[1:] descending = True field = getattr(self.model, name) if descending: field = desc(field) return field if ordering: qs = qs.order_by(*map(lambda x: map_field(x), ordering)) return qs
Example #4
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 #5
Source File: test_operators.py From sqlalchemy with MIT License | 5 votes |
def test_single_bool_one(self): self.assert_compile(~and_(true()), "false")
Example #6
Source File: test_operators.py From sqlalchemy with MIT License | 5 votes |
def test_seven_b(self): t1 = table("t1", column("a")) t2 = table("t2", column("b")) self.assert_compile( join(t1, t2, onclause=false()), "t1 JOIN t2 ON 0 = 1", dialect=self._dialect(False), )
Example #7
Source File: test_operators.py From sqlalchemy with MIT License | 5 votes |
def test_single_bool_two(self): self.assert_compile(~and_(True), "false")
Example #8
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 #9
Source File: test_operators.py From sqlalchemy with MIT License | 5 votes |
def test_single_bool_four(self): self.assert_compile(~or_(false()), "true")
Example #10
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 #11
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 #12
Source File: test_operators.py From sqlalchemy with MIT License | 5 votes |
def test_eight(self): x = column("x") self.assert_compile( or_(false(), x == 7, false(), x == 9), "x = :x_1 OR x = :x_2" )
Example #13
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 #14
Source File: test_operators.py From sqlalchemy with MIT License | 5 votes |
def test_constants_are_singleton(self): is_(null(), null()) is_(false(), false()) is_(true(), true())
Example #15
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 #16
Source File: test_operators.py From sqlalchemy with MIT License | 5 votes |
def test_is_false_literal(self): c = column("x", Boolean) self.assert_compile(c.is_(False), "x IS false")
Example #17
Source File: test_operators.py From sqlalchemy with MIT License | 5 votes |
def test_and_false_literal_leading(self): self.assert_compile(and_(False, True), "false") self.assert_compile(and_(False, False), "false")
Example #18
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 #19
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 #20
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 #21
Source File: views.py From koschei with GNU General Public License v2.0 | 5 votes |
def populate_package_groups(packages): """ Adds `visible_groups` field to package objects. It contains a list of PackageGroup objects that are visible to current user - user is on Group's ACL. Global groups are visible to everyone. Ideally, this would be expressed using a SQLA relationship instead, but realtionships don't allow additional inputs (current user). :param packages: object with base_id attribute that allows adding attributes """ base_map = {} for package in packages: package.visible_groups = [] base_map[package.base_id] = package filter_expr = PackageGroup.namespace == None if g.user: filter_expr |= GroupACL.user_id == g.user.id query = ( db.query(PackageGroupRelation) .options(contains_eager(PackageGroupRelation.group)) .filter( PackageGroupRelation.base_id.in_(base_map.keys()) if base_map else false() ) .join(PackageGroup) .filter(filter_expr) .order_by(PackageGroup.namespace, PackageGroup.name) ) if g.user: query = query.outerjoin(GroupACL) for r in query: base_map[r.base_id].visible_groups.append(r.group)
Example #22
Source File: d4f265e8eb9d_add_default_to_vim.py From tacker with Apache License 2.0 | 5 votes |
def upgrade(active_plugins=None, options=None): op.add_column('vims', sa.Column('is_default', sa.Boolean(), server_default=sql.false(), nullable=False))
Example #23
Source File: db.py From networking-sfc with Apache License 2.0 | 5 votes |
def _get_port_details_by_filter(self, filters=None): qry = self.admin_context.session.query(PortPairDetail) if filters: for key, value in filters.items(): column = getattr(PortPairDetail, key, None) if column: if not value: qry = qry.filter(sql.false()) else: qry = qry.filter(column == value) return qry
Example #24
Source File: model_segment.py From jet-bridge with MIT License | 5 votes |
def get_model_segment_filter(request, Model): mapper = inspect(Model) primary_key = mapper.primary_key[0].name class ModelSegmentFilter(CharFilter): def filter(self, qs, value): value = self.clean_value(value) if value in EMPTY_VALUES: return qs body = self.handler.data if not isinstance(body, dict): return qs.filter(sql.false()) items = list(filter(lambda x: x.get('name') == value, body.get('segments', []))) if len(items) == 0: return qs.filter(sql.false()) query = items[0].get('query') serializer = SqlSerializer(data={'query': query}, context={'request': request}) serializer.is_valid(raise_exception=True) result = serializer.execute() columns = list(result['columns']) rows = result['data'] if len(columns) == 0 or len(rows) == 0: return qs.filter(sql.false()) ids = list(map(lambda x: list(x)[0], rows)) return qs.filter(getattr(Model, primary_key).in_(ids)) return ModelSegmentFilter
Example #25
Source File: model_group.py From jet-bridge with MIT License | 5 votes |
def filter(self, qs, value): if value in EMPTY_VALUES: return qs x_column = getattr(self.model, value['x_column']) y_column = getattr(self.model, value['y_column']) if value['y_func'] == 'count': y_func = func.count(y_column) elif value['y_func'] == 'sum': y_func = func.sum(y_column) elif value['y_func'] == 'min': y_func = func.min(y_column) elif value['y_func'] == 'max': y_func = func.max(y_column) elif value['y_func'] == 'avg': y_func = func.avg(y_column) else: return qs.filter(sql.false()) if value['x_lookup'] and value['x_lookup'] in ['date']: x_lookup = getattr(func, value['x_lookup']) x_func = x_lookup(x_column) else: x_func = x_column qs = qs.session.query(x_func.label('group'), y_func.label('y_func')).group_by('group').order_by('group').all() return qs
Example #26
Source File: test_postgresql.py From alembic with MIT License | 5 votes |
def test_render_server_default_native_boolean(self): c = Column( "updated_at", Boolean(), server_default=false(), nullable=False ) result = autogenerate.render._render_column(c, self.autogen_context) eq_ignore_whitespace( result, "sa.Column('updated_at', sa.Boolean(), " "server_default=sa.text(!U'false'), " "nullable=False)", )
Example #27
Source File: test_autogen_render.py From alembic with MIT License | 5 votes |
def test_render_server_default_non_native_boolean(self): c = Column( "updated_at", Boolean(), server_default=false(), nullable=False ) result = autogenerate.render._render_column(c, self.autogen_context) eq_ignore_whitespace( result, "sa.Column('updated_at', sa.Boolean(), " "server_default=sa.text(!U'0'), " "nullable=False)", )
Example #28
Source File: filtering.py From flask-resty with MIT License | 5 votes |
def get_filter(self, view, arg_value): if arg_value is None: return self.get_default_filter(view) if not arg_value and not self._allow_empty: return sql.false() if not self._separator or self._separator not in arg_value: return self.get_element_filter(view, arg_value) return sa.or_( self.get_element_filter(view, value_raw) for value_raw in arg_value.split(self._separator) )
Example #29
Source File: filtering.py From flask-resty with MIT License | 5 votes |
def get_element_filter(self, view, value): field = self.get_field(view) try: value = self.deserialize(field, value) except ValidationError as e: if self._skip_invalid: return sql.false() raise ApiError.from_validation_error( 400, e, self.format_validation_error ) from e return self.get_filter_clause(view, value)
Example #30
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) )