def wrappar(self, *args, **kwargs): try: #print('something before') result = func(self, *args, **kwargs) dBSession.commit() #print('something after') return result except Exception as e: dBSession.rollback() raise e
def inner_wrappar(*args, **kwargs): try: #print('something before') result = func(*args, **kwargs) dBSession.commit() #print('something after') return result except Exception as e: #print(e) dBSession.rollback() return ExceptionApi(Code.ERROR, e)
def cleanUnreadNumber(room_uuid, user_id): filter = { AddressBook.be_focused_user_id == user_id, AddressBook.room_uuid == room_uuid } dBSession.query(AddressBook).filter( *filter).update({'unread_number': 0, 'updated_at': time.time()}) return dBSession.commit()
def updateUnreadNumber(room_uuid, user_id): filter = { AddressBook.be_focused_user_id != user_id, AddressBook.room_uuid == room_uuid } dBSession.query(AddressBook).filter(*filter).update({ AddressBook.unread_number: AddressBook.unread_number+1, AddressBook.updated_at: time.time() }) return dBSession.commit()
def add(self, data: str, type: int = 1, level: int = 1) -> int: """ 添加 @param: string data @param: int type @param: int level @retrun int boolean """ insertData = {'data': data, 'type': type, 'level': level} try: log = HtLog(**insertData) dBSession.add(log) #dBSession.flush() dBSession.commit() id = log.id return id except Exception as e: dBSession.rollback() return 0
def clientAdd(data: dict) -> int: """ 客户端添加日志 @param: string data @retrun int boolean """ insertData = { 'data': data['data'], 'type': data['type'], 'level': data['level'] } try: log = HtLog(**insertData) dBSession.add(log) dBSession.commit() id = log.id return id except Exception as e: dBSession.rollback() return 0
def cleanUnreadNumber(room_uuid, user_id): # 清除关注者未读消息次数 filter = { UserRoomRelation.user_id == user_id, UserRoomRelation.room_uuid == room_uuid } dBSession.query(UserRoomRelation).filter(*filter).update({ 'unread_number': 0, 'updated_at': time.time() }) return dBSession.commit()
def updateUnreadNumber(room_uuid, user_id): # 更新关注者未读消息 filter = { UserRoomRelation.user_id != user_id, UserRoomRelation.room_uuid == room_uuid } dBSession.query(UserRoomRelation).filter(*filter).update({ UserRoomRelation.unread_number: UserRoomRelation.unread_number + 1, UserRoomRelation.updated_at: time.time() }) return dBSession.commit()
def add(self, data, type=1, level=1): """ 添加 @param: string data @param: integer type @param: integer level @retrun integer boolean """ data = { 'data': data, 'type': type, 'level': level, 'create_time': int(time.time()) } try: log = HtLog(**data) dBSession.add(log) dBSession.flush() id = log.id dBSession.commit() return id except Exception as e: dBSession.rollback() return 0
def update(email, updated_at): dBSession.query(Users).filter_by(email=email).update({'updated_at': updated_at}) return dBSession.commit()
def delete(self, id): self.query.filter_by(id=id).delete() return dBSession.commit()
def add(index, uuid, imgString): data = ImgShard(index=index, uuid=uuid, imgString=imgString) dBSession.add(data) return dBSession.commit()