def decorator(*args, **kwargs): session = kwargs.get('session') if not session: with open_session(Session, commit=commit) as session: kwargs['session'] = session r = func(*args, **kwargs) else: r = func(*args, **kwargs) return r
def add(self, data, session=None): if not data: return -1 if not isinstance(data, list): data = [data] model_ids = [] with open_session(Session, commit=True) as session: for d in data: model = self.model() model.add_model(d) session.add(model) session.flush() model_ids.append(model.id) if len(model_ids) < 2: return model_ids[0] else: return model_ids
def get_all(self, model_id): with open_session(Session) as rs: model = rs.query(self.model).get(model_id) return model
def det_id_del(self): with open_session(Session) as rs: r = rs.query(func.min(self.model.id)).filter_by(is_del=1).scalar() return r