本文整理汇总了Python中pyramid_sqlalchemy.Session.bulk_insert_mappings方法的典型用法代码示例。如果您正苦于以下问题:Python Session.bulk_insert_mappings方法的具体用法?Python Session.bulk_insert_mappings怎么用?Python Session.bulk_insert_mappings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid_sqlalchemy.Session
的用法示例。
在下文中一共展示了Session.bulk_insert_mappings方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete_all
# 需要导入模块: from pyramid_sqlalchemy import Session [as 别名]
# 或者: from pyramid_sqlalchemy.Session import bulk_insert_mappings [as 别名]
def delete_all(self, collection_id, parent_id, filters=None,
with_deleted=True, id_field=DEFAULT_ID_FIELD,
modified_field=DEFAULT_MODIFIED_FIELD,
deleted_field=DEFAULT_DELETED_FIELD,
auth=None):
"""Delete all objects in this `collection_id` for this `parent_id`.
:param str collection_id: the collection id.
:param str parent_id: the collection parent.
:param filters: Optionnally filter the objects to delete.
:type filters: list of :class:`cliquet.storage.Filter`
:param bool with_deleted: track deleted records with a tombstone
:returns: the list of deleted objects, with minimal set of attributes.
:rtype: list of dict
"""
qry = Session.query(self.collection).options(load_only('id'))\
.filter(and_(self.collection.parent_id == parent_id,
getattr(self.collection, deleted_field) == False))
for every in filters:
qry = qry.filter(SQLAFilter(self.collection, every)())
rows = [{"id": every.id, "parent_id": parent_id, "collection_id": collection_id,
modified_field: datetime.datetime.utcnow()} for every in qry.all()]
Session.bulk_update_mappings(self.collection,
[{"id": every['id'], deleted_field: True,
modified_field: every[modified_field]} for every in rows])
if with_deleted:
Session.bulk_insert_mappings(Deleted, rows)
return rows