当前位置: 首页>>代码示例>>Python>>正文


Python Session.bulk_insert_mappings方法代码示例

本文整理汇总了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
开发者ID:marplatense,项目名称:cliquet,代码行数:32,代码来源:__init__.py


注:本文中的pyramid_sqlalchemy.Session.bulk_insert_mappings方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。