def add(self): new_storage_info = m.SnapshotStorage( ident=self.storage_ident, parent_ident=self.parent_ident, parent_timestamp=self.parent_timestamp, type=self.type, disk_bytes=self.disk_bytes, status=self.status, image_path=self.image_path, tree_ident=self.tree_ident, ) with session.SessionForReadWrite() as s: s.add(new_storage_info) s.commit() new_storage_obj = (s.query(m.SnapshotStorage).filter( m.SnapshotStorage.ident == self.storage_ident).first()) return new_storage_obj.obj_to_dict()
def add(self): assert self.normal_create_inst[ 'operation_type'] == m.Journal.TYPE_NORMAL_CREATE new_storage_info = m.SnapshotStorage( ident=self.normal_create_inst.new_ident, parent_ident=self.parent_ident, parent_timestamp=self.parent_timestamp, type=self.normal_create_inst.new_type, disk_bytes=self.normal_create_inst.new_disk_bytes, status=m.SnapshotStorage.STATUS_CREATING, image_path=self.image_path, tree_ident=self.tree_ident, ) with session.SessionForReadWrite() as s: s.add(new_storage_info) s.commit() new_storage_obj = (s.query(m.SnapshotStorage).filter( m.SnapshotStorage.ident == self.normal_create_inst.new_ident).first()) return new_storage_obj.obj_to_dict()
def update(self): with session.SessionForReadWrite() as s: s.query(m.Journal).filter( m.SnapshotStorage.ident == self.ident).update( {self.column_name: self.new_data}) s.commit()
def update(self): with session.SessionForReadWrite() as s: s.query(m.Journal).filter(m.Journal.token == self.token).update( {self.column_name: self.new_data}) s.commit()
def __init__(self, token, column_name, new_data, session_=session.SessionForReadWrite()): self.token = token self.column_name = column_name # 更新的字段名 self.new_data = new_data # 更新的数据 self.session = session_