db.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:centr 作者: ibiBgOR 项目源码 文件源码
def insert_element(self, element):
        s = db.session

        if isinstance(element, DBFeedItem):
            try:
                s.add(element)
                s.commit()
            except exc.IntegrityError, e:
                # we expect integrity errors. The reason is that we may try to regularly insert the same element into the database
                # those elements should not be added to the database and we just rollback the transaction and don't log anything
                s.rollback()
            except Exception, e:
                self._logger.error(str(e))
                s.rollback()
        elif isinstance(element, Feeditem):
            self.insert_element(DBFeedItem(element.content, element.type, element.source, element.time))
        else:
            self._logger.warning('An element could not be inserted into the database, because it is non of the accepted types. (' + type(element) + ')')
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号