本文整理汇总了Python中sqlalchemy.sql.expression.true方法的典型用法代码示例。如果您正苦于以下问题:Python expression.true方法的具体用法?Python expression.true怎么用?Python expression.true使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.sql.expression
的用法示例。
在下文中一共展示了expression.true方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: release_parent_rule
# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import true [as 别名]
def release_parent_rule(child_rule_id, remove_parent_expiration=False, session=None):
"""
Release a potential parent rule, because the child_rule is OK.
:param child_rule_id: The child rule id.
:param remove_parant_expiration: If true, removes the expiration of the parent rule.
:param session: The Database session
"""
session.flush()
parent_rules = session.query(models.ReplicationRule).filter_by(child_rule_id=child_rule_id).\
with_hint(models.ReplicationRule, "index(RULES RULES_CHILD_RULE_ID_IDX)", 'oracle').all()
for rule in parent_rules:
if remove_parent_expiration:
rule.expires_at = None
rule.child_rule_id = None
insert_rule_history(rule=rule, recent=True, longterm=False, session=session)
示例2: _share_type_get_query
# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import true [as 别名]
def _share_type_get_query(context, session=None, read_deleted=None,
expected_fields=None):
expected_fields = expected_fields or []
query = (model_query(context,
models.ShareTypes,
session=session,
read_deleted=read_deleted).
options(joinedload('extra_specs')))
if 'projects' in expected_fields:
query = query.options(joinedload('projects'))
if not context.is_admin:
the_filter = [models.ShareTypes.is_public == true()]
projects_attr = getattr(models.ShareTypes, 'projects')
the_filter.extend([
projects_attr.any(project_id=context.project_id)
])
query = query.filter(or_(*the_filter))
return query
示例3: _share_group_type_get_query
# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import true [as 别名]
def _share_group_type_get_query(context, session=None, read_deleted=None,
expected_fields=None):
expected_fields = expected_fields or []
query = model_query(
context, models.ShareGroupTypes, session=session,
read_deleted=read_deleted
).options(
joinedload('group_specs'),
joinedload('share_types'),
)
if 'projects' in expected_fields:
query = query.options(joinedload('projects'))
if not context.is_admin:
the_filter = [models.ShareGroupTypes.is_public == true()]
projects_attr = getattr(models.ShareGroupTypes, 'projects')
the_filter.extend([
projects_attr.any(project_id=context.project_id)
])
query = query.filter(or_(*the_filter))
return query
示例4: search
# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import true [as 别名]
def search(what, **conditions):
if what == 'codename':
columns = [db.codesTable.c.name]
elif what == 'point':
columns = [simTable.c.identifier, db.codesTable.c.name, db.decodersTable.c.name,
simTable.c.channel_json, simTable.c.wordSeed, simTable.c.samples,
simTable.c.errors, simTable.c.cputime, simTable.c.date_start,
simTable.c.date_end, simTable.c.machine, simTable.c.program_name,
simTable.c.program_version, simTable.c.stats]
else:
raise ValueError('unknown search: "{}"'.format(what))
condition = expression.true()
for key, val in conditions.items():
if key == 'identifier':
condition &= simTable.c.identifier.in_(val)
elif key == 'code':
condition &= db.codesTable.c.name.in_(val)
else:
raise ValueError()
s = sqla.select(columns, whereclause=condition, from_obj=joinTable, distinct=True,
use_labels=True).order_by(db.codesTable.c.name)
ans = db.engine.execute(s).fetchall()
if what == 'point':
return [dataPointFromRow(row) for row in ans]
return db.engine.execute(s).fetchall()
示例5: rbac_filter
# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import true [as 别名]
def rbac_filter(cls, query, mode, user):
public_tasks = query.join(cls.service).filter(
models["service"].public == true()
)
user_tasks = (
query.join(cls.service)
.join(models["access"], models["service"].access)
.join(models["user"], models["access"].users)
.filter(models["user"].name == user.name)
)
user_group_tasks = (
query.join(cls.service)
.join(models["access"], models["service"].access)
.join(models["group"], models["access"].groups)
.join(models["user"], models["group"].users)
.filter(models["user"].name == user.name)
)
return public_tasks.union(user_tasks, user_group_tasks)
示例6: rbac_filter
# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import true [as 别名]
def rbac_filter(cls, query, mode, user):
public_objects = query.filter(cls.public == true())
user_objects = (
query.join(cls.pools)
.join(models["access"], models["pool"].access)
.join(models["user"], models["access"].users)
.filter(models["access"].pools_access.contains(mode))
.filter(models["user"].name == user.name)
)
user_group_objects = (
query.join(cls.pools)
.join(models["access"], models["pool"].access)
.join(models["group"], models["access"].groups)
.join(models["user"], models["group"].users)
.filter(models["access"].pools_access.contains(mode))
.filter(models["user"].name == user.name)
)
return public_objects.union(user_objects, user_group_objects)
示例7: filtering_constraints
# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import true [as 别名]
def filtering_constraints(cls, **kwargs):
workflow_id, constraints = kwargs["form"].get("workflow-filtering"), []
if workflow_id:
constraints.extend(
[
models["service"].workflows.any(
models["workflow"].id == int(workflow_id)
),
~or_(
models["service"].scoped_name == name
for name in ("Start", "End")
),
]
)
elif kwargs["form"].get("parent-filtering", "true") == "true":
constraints.append(~models["service"].workflows.any())
return constraints
示例8: rbac_filter
# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import true [as 别名]
def rbac_filter(cls, query, mode, user):
service_alias = aliased(models["service"])
public_services = query.filter(models["service"].public == true())
user_services = (
query.join(models["service"].originals.of_type(service_alias))
.join(models["access"], service_alias.access)
.join(models["user"], models["access"].users)
.filter(models["access"].services_access.contains(mode))
.filter(models["user"].name == user.name)
)
user_group_services = (
query.join(models["service"].originals.of_type(service_alias))
.join(models["access"], service_alias.access)
.join(models["group"], models["access"].groups)
.join(models["user"], models["group"].users)
.filter(models["access"].services_access.contains(mode))
.filter(models["user"].name == user.name)
)
return public_services.union(user_services, user_group_services)
示例9: upgrade
# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import true [as 别名]
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('agents', sa.Column(
'schedulable', sa.Boolean(),
server_default=true(),
default=True,
nullable=False,
))
# ### end Alembic commands ###
示例10: _list_agents_by_sgroup
# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import true [as 别名]
def _list_agents_by_sgroup(
db_conn: SAConnection,
sgroup_name: str,
) -> Sequence[AgentContext]:
query = (
sa.select([
agents.c.id,
agents.c.addr,
agents.c.scaling_group,
agents.c.available_slots,
agents.c.occupied_slots,
], for_update=True)
.select_from(agents)
.where(
(agents.c.status == AgentStatus.ALIVE) &
(agents.c.scaling_group == sgroup_name) &
(agents.c.schedulable == true())
)
)
items = []
async for row in db_conn.execute(query):
item = AgentContext(
row['id'],
row['addr'],
row['scaling_group'],
row['available_slots'],
row['occupied_slots'],
)
items.append(item)
return items
示例11: report_stats
# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import true [as 别名]
def report_stats(app: web.Application) -> None:
stats_monitor = app['stats_monitor']
await stats_monitor.report_metric(
GAUGE, 'ai.backend.gateway.coroutines', len(asyncio.Task.all_tasks()))
all_inst_ids = [
inst_id async for inst_id
in app['registry'].enumerate_instances()]
await stats_monitor.report_metric(
GAUGE, 'ai.backend.gateway.agent_instances', len(all_inst_ids))
async with app['dbpool'].acquire() as conn, conn.begin():
query = (sa.select([sa.func.sum(keypairs.c.concurrency_used)])
.select_from(keypairs))
n = await conn.scalar(query)
await stats_monitor.report_metric(
GAUGE, 'ai.backend.gateway.active_kernels', n)
subquery = (sa.select([sa.func.count()])
.select_from(keypairs)
.where(keypairs.c.is_active == true())
.group_by(keypairs.c.user_id))
query = sa.select([sa.func.count()]).select_from(subquery.alias())
n = await conn.scalar(query)
await stats_monitor.report_metric(
GAUGE, 'ai.backend.users.has_active_key', n)
subquery = subquery.where(keypairs.c.last_used != null())
query = sa.select([sa.func.count()]).select_from(subquery.alias())
n = await conn.scalar(query)
await stats_monitor.report_metric(
GAUGE, 'ai.backend.users.has_used_key', n)
'''
query = sa.select([sa.func.count()]).select_from(usage)
n = await conn.scalar(query)
await stats_monitor.report_metric(
GAUGE, 'ai.backend.gateway.accum_kernels', n)
'''
示例12: remote_login
# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import true [as 别名]
def remote_login():
auth_token = ub.RemoteAuthToken()
ub.session.add(auth_token)
ub.session.commit()
verify_url = url_for('web.verify_token', token=auth_token.auth_token, _external=true)
log.debug(u"Remot Login request with token: %s", auth_token.auth_token)
return render_title_template('remote_login.html', title=_(u"login"), token=auth_token.auth_token,
verify_url=verify_url, page="remotelogin")
示例13: common_filters
# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import true [as 别名]
def common_filters(self, allow_show_archived=False):
if not allow_show_archived:
archived_books = (
ub.session.query(ub.ArchivedBook)
.filter(ub.ArchivedBook.user_id == int(current_user.id))
.filter(ub.ArchivedBook.is_archived == True)
.all()
)
archived_book_ids = [archived_book.book_id for archived_book in archived_books]
archived_filter = Books.id.notin_(archived_book_ids)
else:
archived_filter = true()
if current_user.filter_language() != "all":
lang_filter = Books.languages.any(Languages.lang_code == current_user.filter_language())
else:
lang_filter = true()
negtags_list = current_user.list_denied_tags()
postags_list = current_user.list_allowed_tags()
neg_content_tags_filter = false() if negtags_list == [''] else Books.tags.any(Tags.name.in_(negtags_list))
pos_content_tags_filter = true() if postags_list == [''] else Books.tags.any(Tags.name.in_(postags_list))
if self.config.config_restricted_column:
pos_cc_list = current_user.allowed_column_value.split(',')
pos_content_cc_filter = true() if pos_cc_list == [''] else \
getattr(Books, 'custom_column_' + str(self.config.config_restricted_column)). \
any(cc_classes[self.config.config_restricted_column].value.in_(pos_cc_list))
neg_cc_list = current_user.denied_column_value.split(',')
neg_content_cc_filter = false() if neg_cc_list == [''] else \
getattr(Books, 'custom_column_' + str(self.config.config_restricted_column)). \
any(cc_classes[self.config.config_restricted_column].value.in_(neg_cc_list))
else:
pos_content_cc_filter = true()
neg_content_cc_filter = false()
return and_(lang_filter, pos_content_tags_filter, ~neg_content_tags_filter,
pos_content_cc_filter, ~neg_content_cc_filter, archived_filter)
# Fill indexpage with all requested data from database
示例14: get_typeahead
# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import true [as 别名]
def get_typeahead(self, database, query, replace=('', ''), tag_filter=true()):
query = query or ''
self.session.connection().connection.connection.create_function("lower", 1, lcase)
entries = self.session.query(database).filter(tag_filter). \
filter(func.lower(database.name).ilike("%" + query + "%")).all()
json_dumps = json.dumps([dict(name=r.name.replace(*replace)) for r in entries])
return json_dumps
示例15: tags_filters
# 需要导入模块: from sqlalchemy.sql import expression [as 别名]
# 或者: from sqlalchemy.sql.expression import true [as 别名]
def tags_filters():
negtags_list = current_user.list_denied_tags()
postags_list = current_user.list_allowed_tags()
neg_content_tags_filter = false() if negtags_list == [''] else db.Tags.name.in_(negtags_list)
pos_content_tags_filter = true() if postags_list == [''] else db.Tags.name.in_(postags_list)
return and_(pos_content_tags_filter, ~neg_content_tags_filter)
# checks if domain is in database (including wildcards)
# example SELECT * FROM @TABLE WHERE 'abcdefg' LIKE Name;
# from https://code.luasoftware.com/tutorials/flask/execute-raw-sql-in-flask-sqlalchemy/