Example #1
0
    def query_all_objs(self):
        """获取所有的数据"""

        with session.SessionForRead() as s:
            objs = (s.query(m.SnapshotStorage).filter(
                m.SnapshotStorage.tree_ident == self.tree_ident).all())
            return objs
Example #2
0
    def is_ident_exist(self):
        """查询某ident是否存在"""

        with session.SessionForRead() as s:
            if s.query(m.SnapshotStorage).filter(
                    m.SnapshotStorage.ident == self.ident).first():
                return True
            else:
                return False
Example #3
0
    def query_valid_objs(self):
        """获取有效的数据"""

        with session.SessionForRead() as s:
            objs = (s.query(m.SnapshotStorage).filter(
                m.SnapshotStorage.tree_ident == self.tree_ident).filter(
                    m.SnapshotStorage.status.notin_(
                        m.SnapshotStorage.INVALID_STORAGE_STATUS)).all())
            return objs
Example #4
0
    def query_objs(self):
        """获取创建日志"""

        with session.SessionForRead() as s:
            q = s.query(m.Journal).filter(m.Journal.consumed_timestamp.is_(None))
            if self.tree_ident:
                q = q.filter(m.Journal.tree_ident == self.tree_ident)
            if self.journal_types:
                q = q.filter(m.Journal.operation_type.in_(self.journal_types))
            return q.order_by(m.Journal.id).all()
Example #5
0
    def get_obj(self):
        """获取数据

        :raise
            JournalNotExist
        """

        with session.SessionForRead() as s:
            obj = s.query(m.Journal).filter(m.Journal.token == self.token).first()
            if not obj:
                raise JournalNotExist(f'not exist token : {self.token}')
            return obj
Example #6
0
    def get_obj(self):
        """获取快照对象"""

        with session.SessionForRead() as s:
            return s.query(m.SnapshotStorage).filter(
                m.SnapshotStorage.ident == self.ident).first()
Example #7
0
 def query(self):
     with session.SessionForRead() as s:
         q = s.query(m.SnapshotStorage).filter(
             m.SnapshotStorage.ident == self.storage_ident).first()
         return q
Example #8
0
 def drop(self):
     with session.SessionForRead() as s:
         q = s.query(m.SnapshotStorage).filter(
             m.SnapshotStorage.ident == self.storage_ident).first()
         s.delete(q)
         s.commit()