本文整理匯總了Python中sqlalchemy.sql.false方法的典型用法代碼示例。如果您正苦於以下問題:Python sql.false方法的具體用法?Python sql.false怎麽用?Python sql.false使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sqlalchemy.sql
的用法示例。
在下文中一共展示了sql.false方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: filter
# 需要導入模塊: from sqlalchemy import sql [as 別名]
# 或者: from sqlalchemy.sql import false [as 別名]
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
示例2: filter
# 需要導入模塊: from sqlalchemy import sql [as 別名]
# 或者: from sqlalchemy.sql import false [as 別名]
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
示例3: test_extra_reserved_words
# 需要導入模塊: from sqlalchemy import sql [as 別名]
# 或者: from sqlalchemy.sql import false [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()
示例4: user_packages
# 需要導入模塊: from sqlalchemy import sql [as 別名]
# 或者: from sqlalchemy.sql import false [as 別名]
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)
示例5: _get_path_nodes_by_filter
# 需要導入模塊: from sqlalchemy import sql [as 別名]
# 或者: from sqlalchemy.sql import false [as 別名]
def _get_path_nodes_by_filter(self, filters=None):
qry = self.admin_context.session.query(PathNode)
if filters:
for key, value in filters.items():
column = getattr(PathNode, key, None)
if column:
if not value:
qry = qry.filter(sql.false())
else:
qry = qry.filter(column == value)
return qry
示例6: _get_port_details_by_filter
# 需要導入模塊: from sqlalchemy import sql [as 別名]
# 或者: from sqlalchemy.sql import false [as 別名]
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
示例7: get_model_segment_filter
# 需要導入模塊: from sqlalchemy import sql [as 別名]
# 或者: from sqlalchemy.sql import false [as 別名]
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
示例8: filter
# 需要導入模塊: from sqlalchemy import sql [as 別名]
# 或者: from sqlalchemy.sql import false [as 別名]
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
示例9: test_render_server_default_native_boolean
# 需要導入模塊: from sqlalchemy import sql [as 別名]
# 或者: from sqlalchemy.sql import false [as 別名]
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)",
)
示例10: test_render_server_default_non_native_boolean
# 需要導入模塊: from sqlalchemy import sql [as 別名]
# 或者: from sqlalchemy.sql import false [as 別名]
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)",
)
示例11: get_filter
# 需要導入模塊: from sqlalchemy import sql [as 別名]
# 或者: from sqlalchemy.sql import false [as 別名]
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)
)
示例12: get_element_filter
# 需要導入模塊: from sqlalchemy import sql [as 別名]
# 或者: from sqlalchemy.sql import false [as 別名]
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)
示例13: upgrade
# 需要導入模塊: from sqlalchemy import sql [as 別名]
# 或者: from sqlalchemy.sql import false [as 別名]
def upgrade(active_plugins=None, options=None):
op.add_column('vims', sa.Column('is_default',
sa.Boolean(),
server_default=sql.false(),
nullable=False))
示例14: test_boolean_default
# 需要導入模塊: from sqlalchemy import sql [as 別名]
# 或者: from sqlalchemy.sql import false [as 別名]
def test_boolean_default(self):
t = Table(
"t",
self.metadata,
Column("x", Boolean, server_default=sql.false()),
)
t.create(testing.db)
with testing.db.connect() as conn:
conn.execute(t.insert())
conn.execute(t.insert().values(x=True))
eq_(
conn.execute(t.select().order_by(t.c.x)).fetchall(),
[(False,), (True,)],
)
示例15: test_true_false
# 需要導入模塊: from sqlalchemy import sql [as 別名]
# 或者: from sqlalchemy.sql import false [as 別名]
def test_true_false(self):
self.assert_compile(sql.false(), "0")
self.assert_compile(sql.true(), "1")