示例#1
0
 def del_by_id(cls, poiId):
     try:
         Database.delete_one_by(Meishi, Meishi.poiId == poiId)
         Database.commit()
         return True
     except Exception as e:
         Database.rollback()
示例#2
0
 def load_or_create(cls, poiId, frontImg, title, avgScore, allCommentNum,
                    address, avgPrice, dealList):
     meishi_obj = cls.by_id(poiId)
     if meishi_obj:
         return meishi_obj
     meishi_obj = cls(
         poiId=poiId,
         frontImg=frontImg,
         title=title,
         avgScore=avgScore,
         allCommentNum=allCommentNum,
         address=address,
         avgPrice=avgPrice,
         dealList=dealList,
     )
     try:
         Database.add(meishi_obj)
         Database.commit()
         return meishi_obj
     #TODO(weiming liu) cache sqlalchemy for not cache base exception
     except Exception as e:
         log.error(str(e))
         Database.rollback()
         # TODO(weiming liu) raise error for not return None
         return None
示例#3
0
 def del_by_id(cls, user_id):
     try:
         Database.delete_one_by(User, User.id == user_id)
         Database.commit()
         return True
     except Exception as e:
         Database.rollback()
         return False
示例#4
0
 def del_by_id(cls, file_id):
     try:
         Database.delete_one_by(Dianying, Dianying.file_id == file_id)
         Database.commit()
         return True
     except Exception as e:
         Database.rollback()
         return False
示例#5
0
 def del_by_hash_id(cls, hash_id):
     try:
         Database.delete_one_by(Programming, Programming.hash_id == hash_id)
         Database.commit()
         return True
     except Exception as e:
         Database.rollback()
         return False
示例#6
0
 def load_or_create(cls, hash_id, title, url):
     programming_obj = cls.by_hash_id(hash_id)
     if programming_obj:
         return programming_obj
     programming_obj = cls(
         hash_id=hash_id,
         title=title,
         url=url,
     )
     try:
         Database.add(programming_obj)
         Database.commit()
         return programming_obj
     #TODO(weiming liu) cache sqlalchemy for not cache base exception
     except Exception as e:
         Database.rollback()
         log.error(str(e))
         # TODO(weiming liu) raise error for not return None
         return None
示例#7
0
 def load_or_create(cls, username, password):
     user_obj = cls.by_name(username)
     if user_obj:
         if user_obj.password == password:
             return user_obj
         else:
             raise ArgsError('unmatch password')
     user_obj = cls(
         username=username,
         password=password,
     )
     try:
         Database.add(user_obj)
         Database.commit()
         return user_obj
     #TODO(weiming liu) cache sqlalchemy error for not cache base exception
     except Exception as e:
         log.error(str(e))
         Database.rollback()
         raise DatabaseError('can not create user {username}'.format(username=username))