本文整理汇总了Python中sqlalchemy.or_方法的典型用法代码示例。如果您正苦于以下问题:Python sqlalchemy.or_方法的具体用法?Python sqlalchemy.or_怎么用?Python sqlalchemy.or_使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy
的用法示例。
在下文中一共展示了sqlalchemy.or_方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_online_admins
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import or_ [as 别名]
def get_online_admins(self, session=None) -> list:
admins = session.query(GlobalRoles).filter(or_(
GlobalRoles.roles.ilike('%{}%'.format(RoleKeys.SUPER_USER)),
GlobalRoles.roles.ilike('%{}%'.format(RoleKeys.GLOBAL_MODERATOR))
)).all()
admin_ids = [admin.user_id for admin in admins]
if len(admin_ids) == 0:
return []
online_admins = session.query(UserStatus)\
.filter(UserStatus.status.in_([
UserKeys.STATUS_INVISIBLE,
UserKeys.STATUS_AVAILABLE,
UserKeys.STATUS_CHAT]))\
.filter(UserStatus.uuid.in_(admin_ids)).all()
return [admin.uuid for admin in online_admins]
示例2: get_ranking
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import or_ [as 别名]
def get_ranking(config):
routes = []
session = db.session
for r in level.routes:
rl = []
for user, levels, timestamp in \
session.query(User, db.func.count(LevelState.level),db.func.max(LevelState.timestamp)).\
join(LevelState).\
filter(LevelState.route==r.name).\
filter(LevelState.timestamp < config['END_TIME']).\
filter(LevelState.state=='solved').\
filter(or_(User.seat == None, User.seat != 'Control')).\
group_by(User):
rl.append(Score(user, levels, timestamp))
routes.append(rl)
combined, routes, global_prizes, route_prizes = rank(routes, config)
grank = map_ranking(1, combined, global_prizes)
rrank = [map_ranking(1 + config['GLOBAL_PRIZES'], routes[i], route_prizes[i]) for i in range(len(routes))]
return grank, rrank
示例3: add_item
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import or_ [as 别名]
def add_item(context, kind, data):
item_ref = models.Item()
item_ref.update({
"project_id": context.project_id,
"id": _new_id(kind),
})
item_ref.update(_pack_item_data(data))
try:
item_ref.save()
except db_exception.DBDuplicateEntry as ex:
if (models.ITEMS_OS_ID_INDEX_NAME not in ex.columns and
'os_id' not in ex.columns):
raise
item_ref = (model_query(context, models.Item).
filter_by(os_id=data["os_id"]).
filter(or_(models.Item.project_id == context.project_id,
models.Item.project_id.is_(None))).
filter(models.Item.id.like('%s-%%' % kind)).
one())
item_data = _unpack_item_data(item_ref)
item_data.update(data)
item_ref.update(_pack_item_data(item_data))
item_ref.project_id = context.project_id
item_ref.save()
return _unpack_item_data(item_ref)
示例4: delete_tags
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import or_ [as 别名]
def delete_tags(context, item_ids, tag_pairs=None):
if not item_ids:
return
query = (model_query(context, models.Tag).
filter_by(project_id=context.project_id).
filter(models.Tag.item_id.in_(item_ids)))
if tag_pairs:
tag_fltr = None
for tag_pair in tag_pairs:
pair_fltr = None
for col in ('key', 'value'):
if col in tag_pair:
expr = getattr(models.Tag, col) == tag_pair[col]
pair_fltr = (expr if pair_fltr is None else
and_(pair_fltr, expr))
if pair_fltr is not None:
tag_fltr = (pair_fltr if tag_fltr is None else
or_(tag_fltr, pair_fltr))
if tag_fltr is not None:
query = query.filter(tag_fltr)
query.delete(synchronize_session=False)
示例5: __or__
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import or_ [as 别名]
def __or__(self, other):
"""Implement the ``|`` operator.
When used with SQL expressions, results in an
OR operation, equivalent to
:func:`~.expression.or_`, that is::
a | b
is equivalent to::
from sqlalchemy import or_
or_(a, b)
Care should be taken when using ``|`` regarding
operator precedence; the ``|`` operator has the highest precedence.
The operands should be enclosed in parenthesis if they contain
further sub expressions::
(a == 2) | (b == 4)
"""
return self.operate(or_, other)
示例6: get_and_lock_file_replicas
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import or_ [as 别名]
def get_and_lock_file_replicas(scope, name, nowait=False, restrict_rses=None, session=None):
"""
Get file replicas for a specific scope:name.
:param scope: The scope of the did.
:param name: The name of the did.
:param nowait: Nowait parameter for the FOR UPDATE statement
:param restrict_rses: Possible RSE_ids to filter on.
:param session: The db session in use.
:returns: List of SQLAlchemy Replica Objects
"""
query = session.query(models.RSEFileAssociation).filter_by(scope=scope, name=name).filter(models.RSEFileAssociation.state != ReplicaState.BEING_DELETED)
if restrict_rses is not None:
if len(restrict_rses) < 10:
rse_clause = []
for rse_id in restrict_rses:
rse_clause.append(models.RSEFileAssociation.rse_id == rse_id)
if rse_clause:
query = query.filter(or_(*rse_clause))
return query.with_for_update(nowait=nowait).all()
示例7: get_source_replicas
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import or_ [as 别名]
def get_source_replicas(scope, name, source_rses=None, session=None):
"""
Get soruce replicas for a specific scope:name.
:param scope: The scope of the did.
:param name: The name of the did.
:param soruce_rses: Possible RSE_ids to filter on.
:param session: The db session in use.
:returns: List of SQLAlchemy Replica Objects
"""
query = session.query(models.RSEFileAssociation.rse_id).filter_by(scope=scope, name=name).filter(models.RSEFileAssociation.state == ReplicaState.AVAILABLE)
if source_rses:
if len(source_rses) < 10:
rse_clause = []
for rse_id in source_rses:
rse_clause.append(models.RSEFileAssociation.rse_id == rse_id)
if rse_clause:
query = query.filter(or_(*rse_clause))
return [a[0] for a in query.all()]
示例8: bulk_delete_bad_pfns
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import or_ [as 别名]
def bulk_delete_bad_pfns(pfns, session=None):
"""
Bulk delete bad PFNs.
:param pfns: the list of new files.
:param session: The database session in use.
:returns: True is successful.
"""
pfn_clause = []
for pfn in pfns:
pfn_clause.append(models.BadPFNs.path == pfn)
for chunk in chunks(pfn_clause, 100):
query = session.query(models.BadPFNs).filter(or_(*chunk))
query.delete(synchronize_session=False)
return True
示例9: list_exceptions
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import or_ [as 别名]
def list_exceptions(exception_id, states, session=None):
"""
List exceptions to Lifetime Model.
:param exception_id: The id of the exception
:param states: The states to filter
:param session: The database session in use.
"""
state_clause = []
if states:
state_clause = [models.LifetimeExceptions.state == state for state in states]
query = session.query(models.LifetimeExceptions)
if state_clause != []:
query = query.filter(or_(*state_clause))
if exception_id:
query = query.filter_by(id=exception_id)
for exception in query.yield_per(5):
yield {'id': exception.id, 'scope': exception.scope, 'name': exception.name,
'did_type': exception.did_type, 'account': exception.account,
'pattern': exception.pattern, 'comments': exception.comments,
'state': exception.state, 'created_at': exception.created_at,
'expires_at': exception.expires_at}
示例10: get_metadata_bulk
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import or_ [as 别名]
def get_metadata_bulk(dids, session=None):
"""
Get metadata for a list of dids
:param dids: A list of dids.
:param session: The database session in use.
"""
condition = []
for did in dids:
condition.append(and_(models.DataIdentifier.scope == did['scope'],
models.DataIdentifier.name == did['name']))
try:
for chunk in chunks(condition, 50):
for row in session.query(models.DataIdentifier).with_hint(models.DataIdentifier, "INDEX(DIDS DIDS_PK)", 'oracle').filter(or_(*chunk)):
data = {}
for column in row.__table__.columns:
data[column.name] = getattr(row, column.name)
yield data
except NoResultFound:
raise exception.DataIdentifierNotFound('No Data Identifiers found')
示例11: delete_messages
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import or_ [as 别名]
def delete_messages(messages, session=None):
"""
Delete all messages with the given IDs, and archive them to the history.
:param messages: The messages to delete as a list of dictionaries.
"""
message_condition = []
for message in messages:
message_condition.append(Message.id == message['id'])
if len(message['payload']) > 4000:
message['payload_nolimit'] = message.pop('payload')
try:
if message_condition:
session.query(Message).\
with_hint(Message, "index(messages MESSAGES_ID_PK)", 'oracle').\
filter(or_(*message_condition)).\
delete(synchronize_session=False)
session.bulk_insert_mappings(MessageHistory, messages)
except IntegrityError as e:
raise RucioException(e.args)
示例12: delete_volatile_replicas
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import or_ [as 别名]
def delete_volatile_replicas(rse_id, replicas, session=None):
"""
Bulk delete volatile replicas.
:param rse_id: the rse id.
:param replicas: the list of volatile replicas.
:param session: The database session in use.
:returns: True is successful.
"""
# first check that the rse is a volatile one
try:
session.query(models.RSE.id).filter_by(rse_id=rse_id, volatile=True).one()
except NoResultFound:
raise exception.UnsupportedOperation('No volatile rse found for %s !' % get_rse_name(rse_id=rse_id, session=session))
conditions = []
for replica in replicas:
conditions.append(and_(models.RSEFileAssociation.scope == replica['scope'],
models.RSEFileAssociation.name == replica['name']))
if conditions:
session.query(models.RSEFileAssociation).\
filter(models.RSEFileAssociation.rse_id == rse_id).\
filter(or_(*conditions)).\
delete(synchronize_session=False)
示例13: search_vulnerabilities_numerical
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import or_ [as 别名]
def search_vulnerabilities_numerical(searched_text, db_table):
"""
Perform a search based on vulnerabilities' description, file, id, and port (only if it is an exploit) for an only
numerical search input.
:param searched_text: the search input.
:param db_table: the DB table in which we want to perform the search.
:return: a queryset with search results.
"""
session = start_session()
if db_table == 'searcher_exploit':
queryset = session.query(Exploit).filter(or_(Exploit.description.contains(searched_text),
Exploit.id == int(searched_text),
Exploit.file.contains(searched_text),
Exploit.port == int(searched_text)
))
else:
queryset = session.query(Shellcode).filter(or_(Shellcode.description.contains(searched_text),
Shellcode.id == int(searched_text),
Shellcode.file.contains(searched_text)
))
session.close()
return queryset2list(queryset)
示例14: get_user_filters
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import or_ [as 别名]
def get_user_filters(user):
clauses = []
sfq = db.session.query(SampleFilter)
clauses.append(SampleFilter.user_id == user.user_id)
if not user.is_admin:
clauses.append(SampleFilter.is_public == True)
sfq.filter(or_(*clauses))
sfs = sfq.all()
data = [
{
"name": x.sample_filter_name,
"set": x.sample_filter_tag,
"id": x.sample_filter_id,
"filters": json.loads(x.sample_filter_data),
}
for x in sfs
]
return data
示例15: get_any_relation_of
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import or_ [as 别名]
def get_any_relation_of(self, *pids):
"""Get any relation when given PIDs are parent or child.
:arg pids: one or multiple PIDs
"""
all_relation_pids = set()
for pid in pids:
query = PIDRelation.query.filter_by(
relation_type=self.relation_type.id
).filter(or_(PIDRelation.parent == pid, PIDRelation.child == pid))
results = query.all()
if results:
parent = results[0].parent
if parent == pid:
for result in results:
all_relation_pids.add(result)
else:
# get relations of the parent
for result in self.get_relations_by_parent(parent):
all_relation_pids.add(result)
return list(all_relation_pids)