本文整理汇总了Python中c2corg_api.models.DBSession.execute方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.execute方法的具体用法?Python DBSession.execute怎么用?Python DBSession.execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类c2corg_api.models.DBSession
的用法示例。
在下文中一共展示了DBSession.execute方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_cache_version_direct
# 需要导入模块: from c2corg_api.models import DBSession [as 别名]
# 或者: from c2corg_api.models.DBSession import execute [as 别名]
def update_cache_version_direct(document_id):
""" Update the cache version for the document with the given id
without updating any dependencies.
"""
DBSession.execute(
text('SELECT guidebook.increment_cache_version(:document_id)'),
{'document_id': document_id}
)
示例2: update_activities_of_changes
# 需要导入模块: from c2corg_api.models import DBSession [as 别名]
# 或者: from c2corg_api.models.DBSession import execute [as 别名]
def update_activities_of_changes(document):
"""Update the activities of all feed entries of the given document.
"""
DBSession.execute(
DocumentChange.__table__.update().
where(DocumentChange.document_id == document.document_id).
values(activities=document.activities)
)
示例3: update_cache_version_for_map
# 需要导入模块: from c2corg_api.models import DBSession [as 别名]
# 或者: from c2corg_api.models.DBSession import execute [as 别名]
def update_cache_version_for_map(topo_map):
""" Invalidate the cache keys of all documents that are currently
associated to the given map.
Note that the cache key of the map itself is not changed when calling this
function.
"""
DBSession.execute(
text('SELECT guidebook.update_cache_version_for_map(:document_id)'),
{'document_id': topo_map.document_id}
)
示例4: remove_token
# 需要导入模块: from c2corg_api.models import DBSession [as 别名]
# 或者: from c2corg_api.models.DBSession import execute [as 别名]
def remove_token(token):
now = datetime.datetime.utcnow()
condition = Token.value == token and Token.expire > now
result = DBSession.execute(Token.__table__.delete().where(condition))
if result.rowcount == 0:
log.debug("Failed to remove token %s" % token)
DBSession.flush()
示例5: update_map
# 需要导入模块: from c2corg_api.models import DBSession [as 别名]
# 或者: from c2corg_api.models.DBSession import execute [as 别名]
def update_map(topo_map, reset=False):
"""Create associations for the given map with all intersecting documents.
If `reset` is True, all possible existing associations to this map are
dropped before creating new associations.
"""
if reset:
DBSession.execute(
TopoMapAssociation.__table__.delete().where(
TopoMapAssociation.topo_map_id == topo_map.document_id)
)
if topo_map.redirects_to:
# ignore forwarded maps
return
map_geom = select([DocumentGeometry.geom_detail]). \
where(DocumentGeometry.document_id == topo_map.document_id)
intersecting_documents = DBSession. \
query(
DocumentGeometry.document_id, # id of a document
literal_column(str(topo_map.document_id))). \
join(
Document,
and_(
Document.document_id == DocumentGeometry.document_id,
Document.type != MAP_TYPE)). \
filter(Document.redirects_to.is_(None)). \
filter(
or_(
DocumentGeometry.geom.ST_Intersects(
map_geom.label('t1')),
DocumentGeometry.geom_detail.ST_Intersects(
map_geom.label('t2'))
))
DBSession.execute(
TopoMapAssociation.__table__.insert().from_select(
[TopoMapAssociation.document_id, TopoMapAssociation.topo_map_id],
intersecting_documents))
# update cache key for now associated docs
update_cache_version_for_map(topo_map)
示例6: update_areas_of_changes
# 需要导入模块: from c2corg_api.models import DBSession [as 别名]
# 或者: from c2corg_api.models.DBSession import execute [as 别名]
def update_areas_of_changes(document):
"""Update the area ids of all feed entries of the given document.
"""
areas_select = select(
[
# concatenate with empty array to avoid null values
# select ARRAY[]::integer[] || array_agg(area_id)
literal_column('ARRAY[]::integer[]').op('||')(
func.array_agg(
AreaAssociation.area_id,
type_=postgresql.ARRAY(Integer)))
]).\
where(AreaAssociation.document_id == document.document_id)
DBSession.execute(
DocumentChange.__table__.update().
where(DocumentChange.document_id == document.document_id).
values(area_ids=areas_select.as_scalar())
)
示例7: update_maps_for_document
# 需要导入模块: from c2corg_api.models import DBSession [as 别名]
# 或者: from c2corg_api.models.DBSession import execute [as 别名]
def update_maps_for_document(document, reset=False):
"""Create associations for the given documents with all intersecting maps.
If `reset` is True, all possible existing associations to this document are
dropped before creating new associations.
"""
if reset:
DBSession.execute(
TopoMapAssociation.__table__.delete().where(
TopoMapAssociation.document_id == document.document_id)
)
if document.redirects_to:
# ignore forwarded maps
return
document_geom = select([DocumentGeometry.geom]). \
where(DocumentGeometry.document_id == document.document_id)
document_geom_detail = select([DocumentGeometry.geom_detail]). \
where(DocumentGeometry.document_id == document.document_id)
intersecting_maps = DBSession. \
query(
DocumentGeometry.document_id, # id of a map
literal_column(str(document.document_id))). \
join(
TopoMap,
TopoMap.document_id == DocumentGeometry.document_id). \
filter(TopoMap.redirects_to.is_(None)). \
filter(
or_(
DocumentGeometry.geom_detail.ST_Intersects(
document_geom.label('t1')),
DocumentGeometry.geom_detail.ST_Intersects(
document_geom_detail.label('t2'))
))
DBSession.execute(
TopoMapAssociation.__table__.insert().from_select(
[TopoMapAssociation.topo_map_id, TopoMapAssociation.document_id],
intersecting_maps))
示例8: update_area
# 需要导入模块: from c2corg_api.models import DBSession [as 别名]
# 或者: from c2corg_api.models.DBSession import execute [as 别名]
def update_area(area, reset=False):
"""Create associations for the given area with all intersecting documents.
If `reset` is True, all possible existing associations to this area are
dropped before creating new associations.
"""
if reset:
DBSession.execute(
AreaAssociation.__table__.delete().where(
AreaAssociation.area_id == area.document_id)
)
if area.redirects_to:
# ignore forwarded areas
return
area_geom = select([DocumentGeometry.geom_detail]). \
where(DocumentGeometry.document_id == area.document_id)
intersecting_documents = DBSession. \
query(
DocumentGeometry.document_id, # id of a document
literal_column(str(area.document_id))). \
join(
Document,
and_(
Document.document_id == DocumentGeometry.document_id,
Document.type != AREA_TYPE)). \
filter(Document.redirects_to.is_(None)). \
filter(
or_(
DocumentGeometry.geom.ST_Intersects(
area_geom.label('t1')),
DocumentGeometry.geom_detail.ST_Intersects(
area_geom.label('t2'))
))
DBSession.execute(
AreaAssociation.__table__.insert().from_select(
[AreaAssociation.document_id, AreaAssociation.area_id],
intersecting_documents))
示例9: update_participants_of_outing
# 需要导入模块: from c2corg_api.models import DBSession [as 别名]
# 或者: from c2corg_api.models.DBSession import execute [as 别名]
def update_participants_of_outing(outing_id, user_id):
existing_change = get_existing_change(outing_id)
if not existing_change:
log.warn('no feed change for document {}'.format(outing_id))
return
participant_ids = _get_participants_of_outing(outing_id)
if set(existing_change.user_ids) == set(participant_ids):
# participants have not changed, stop
return
existing_change.user_ids = participant_ids
if existing_change.user_id != user_id:
# a different user is doing this change, only set a different user id
# if the user is one of the participants (to ignore moderator edits)
if user_id in participant_ids:
existing_change.user_id = user_id
existing_change.change_type = 'updated'
existing_change.time = func.now()
DBSession.flush()
# now also update the participants of other feed entries of the outing:
# set `user_ids` to the union of the participant ids and the `user_id` of
# the entry
participants_and_editor = text(
'ARRAY(SELECT DISTINCT UNNEST(array_cat('
' ARRAY[guidebook.feed_document_changes.user_id], :participants)) '
'ORDER BY 1)')
DBSession.execute(
DocumentChange.__table__.update().
where(DocumentChange.document_id == outing_id).
where(DocumentChange.change_id != existing_change.change_id).
values(user_ids=participants_and_editor),
{'participants': participant_ids}
)
示例10: update_cache_version_associations
# 需要导入模块: from c2corg_api.models import DBSession [as 别名]
# 或者: from c2corg_api.models.DBSession import execute [as 别名]
def update_cache_version_associations(
added_associations, removed_associations, ignore_document_id=None):
changed_associations = added_associations + removed_associations
if not changed_associations:
return
documents_to_update = set()
waypoints_to_update = set()
routes_to_update = set()
for association in changed_associations:
documents_to_update.add(association['parent_id'])
documents_to_update.add(association['child_id'])
if association['parent_type'] == WAYPOINT_TYPE and \
association['child_type'] == ROUTE_TYPE:
waypoints_to_update.add(association['parent_id'])
elif association['parent_type'] == ROUTE_TYPE and \
association['child_type'] == OUTING_TYPE:
routes_to_update.add(association['parent_id'])
if ignore_document_id is not None:
documents_to_update.remove(ignore_document_id)
if documents_to_update:
# update the cache version of the documents of added and removed
# associations
DBSession.execute(
text('SELECT guidebook.increment_cache_versions(:document_ids)'),
{'document_ids': list(documents_to_update)}
)
if waypoints_to_update:
# if an association between waypoint and route was removed/added,
# the waypoint parents and grand-parents have to be updated
DBSession.execute(
text('SELECT guidebook.update_cache_version_of_waypoints(:waypoint_ids)'), # noqa: E501
{'waypoint_ids': list(waypoints_to_update)}
)
if routes_to_update:
# if an association between route and outing was removed/added,
# waypoints (and parents and grand-parents) associated to the route
# have to be updated
DBSession.execute(
text('SELECT guidebook.update_cache_version_of_routes(:route_ids)'), # noqa: E501
{'route_ids': list(routes_to_update)}
)
示例11: update_cache_version
# 需要导入模块: from c2corg_api.models import DBSession [as 别名]
# 或者: from c2corg_api.models.DBSession import execute [as 别名]
def update_cache_version(document):
DBSession.execute(
text('SELECT guidebook.update_cache_version(:document_id, :type)'),
{'document_id': document.document_id, 'type': document.type}
)