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
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
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
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()
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
def get_obj(self): """获取快照对象""" with session.SessionForRead() as s: return s.query(m.SnapshotStorage).filter( m.SnapshotStorage.ident == self.ident).first()
def query(self): with session.SessionForRead() as s: q = s.query(m.SnapshotStorage).filter( m.SnapshotStorage.ident == self.storage_ident).first() return q
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()