def paginate(cls, page=1, page_size=10, userId=None): start = page_size * (page - 1) end = page * page_size if userId: return dbSession.query(cls).filter( CheckInRecordModel.userId == userId).order_by( -cls.createTime).slice(start, end).all() else: return dbSession.query(cls).order_by(-cls.createTime).slice( start, end).all()
def paginate(cls, page=1, page_size=10, location=None): start = page_size * (page - 1) end = page * page_size if location: return dbSession.query(cls).filter( SariNews.provinceName.like( '%{}%'.format(location))).order_by(-cls.pubDate).slice( start, end).all() else: return dbSession.query(cls).order_by(-cls.pubDate).slice( start, end).all()
def update(self, **kwargs): """根据实例更新数据""" kwargs['updateTime'] = datetime.now() row = dbSession.query(Orders).filter_by(uuid=self.uuid).first() for k, v in kwargs.items(): setattr(row, k, v) dbSession.commit() return row
def verify_code(cls, phone, code): row = dbSession.query(cls).filter(cls.phone == phone).first() if row: if row.is_expired(): dbSession.delete(row) dbSession.commit() return False, "您的验证码过期" else: if row.code == code: dbSession.delete(row) dbSession.commit() return True, "验证成功" else: dbSession.delete(row) dbSession.commit() return False, "您的验证码无效, 请重新申请" else: return False, "您的验证码无效"
def update_and_insert(cls, **kwargs): name = kwargs.get('companyName') row = dbSession.query(cls) \ .filter(Company.companyName == name) \ .first() if row: logger.debug(f"{name} 已经存在 更新数据") try: for k, v in kwargs.items(): setattr(row, k, v) dbSession.commit() except Exception as e: logger.error("Update Error " + str(e)) else: logger.debug(f"{name} 不存在 新增数据") try: new_row = Company(**kwargs) dbSession.add(new_row) dbSession.commit() except Exception as e: logger.error("Insert Error " + str(e))
def update_and_insert(cls, **kwargs): province = kwargs.get('provinceName') city = kwargs.get('cityName') row = dbSession.query(cls) \ .filter(and_(SariRecord.provinceName.like('%{}%'.format(province)), SariRecord.cityName == city)) \ .first() if row: logger.debug("已经存在 更新数据") try: for k, v in kwargs.items(): setattr(row, k, v) dbSession.commit() except Exception as e: logger.error("Update Error " + str(e)) else: logger.debug("不存在 新增数据") try: new_row = SariRecord(**kwargs) dbSession.add(new_row) dbSession.commit() except Exception as e: logger.error("Insert Error " + str(e))
def update_and_insert(cls, **kwargs): infectSource = kwargs.get('infectSource') updateTime = int(str(kwargs.get('updateTime'))[:-3]) if kwargs.get( 'updateTime') else None row = dbSession.query(cls) \ .filter(and_(SariOverall.infectSource == infectSource, SariRecord.updateTime == updateTime)) \ .first() if row: logger.debug("头条 已经存在 更新数据") try: for k, v in kwargs.items(): setattr(row, k, v) dbSession.commit() except Exception as e: logger.error("Update Error " + str(e)) else: logger.debug("头条 不存在 新增数据") try: new_row = SariOverall(**kwargs) dbSession.add(new_row) dbSession.commit() except Exception as e: logger.error("Insert Error " + str(e))
def update_and_insert(cls, **kwargs): title = kwargs.get('title') pubDate = int(str( kwargs.get('pubDate'))[:-3]) if kwargs.get('pubDate') else None row = dbSession.query(cls) \ .filter(and_(SariNews.title == title, SariNews.pubDate == pubDate)) \ .first() if row: logger.debug("新闻 已经存在 更新数据") try: for k, v in kwargs.items(): setattr(row, k, v) dbSession.commit() except Exception as e: logger.error("Update Error " + str(e)) else: logger.debug("新闻 不存在 新增数据") try: new_row = SariNews(**kwargs) dbSession.add(new_row) dbSession.commit() except Exception as e: logger.error("Insert Error " + str(e))
def by_user_id(cls, kid, page=1, page_size=10): start = page_size * (page - 1) end = page * page_size return dbSession.query(cls).filter_by( userId=kid).order_by(-cls.createTime).slice(start, end).all()
def by_country(cls): return dbSession.query(cls).filter(SariRecord.country != '中国').all()
def by_name(cls, name): return dbSession.query(cls)\ .filter(User.userName.like('%{}%'.format(name))).all()
def by_name(cls, name): return dbSession.query(cls)\ .filter(Company.companyName.like('%{}%'.format(name))).all()
def inQueue(self): return len(dbSession.query(Orders).filter(and_(Orders.id < self.id, Orders.Status == Orders.COMMIT)).all())
def by_address(cls, address, limit=10): return dbSession.query(cls).filter(cls.Address.like('%{}%'.format(address))).limit(limit)
def all(cls): return dbSession.query(cls).order_by(-cls.createTime).all()
def by_id(cls, _id): return dbSession.query(cls).filter(cls.id == _id).first()
def by_id(cls, kid): return dbSession.query(cls).filter_by(id=kid).first()
def by_limit(cls, num): return dbSession.query(cls).order_by(-cls.updateTime).limit(num)
def by_lasted(cls): return dbSession.query(cls).order_by(-cls.updateTime).first()
def by_phone(cls, userPhone): return dbSession.query(cls).filter_by(userPhone=userPhone).first()
def by_id_card(cls, id_card): return dbSession.query(cls).filter_by(userIdCard=id_card).first()
def order_over(cls, uuid): order = dbSession.query(cls).filter(cls.uuid == uuid).first() if order: order.Status = Orders.SUCCESS order.updatedTime = datetime.now() dbSession.commit()
def get_one(cls, key, eType, msgType): return dbSession.query(cls) \ .filter(and_(AuthReplyModel.EventKey == key, AuthReplyModel.EventType == eType, AuthReplyModel.MsgType == msgType)) \ .first()
def by_user_id(cls, user_id): return dbSession.query(cls).order_by(-cls.createdTime).filter(cls.userId == user_id).all()
def paginate(cls, page=1, page_size=10): start = page_size * (page - 1) end = page * page_size return dbSession.query(cls).order_by(-cls.createTime).slice( start, end).all()
def hot_product(cls): return dbSession.query(cls).filter_by(isHot=True).order_by(-cls.createdTime).all()
def all(cls): return dbSession.query(cls).all()
def by_lasted(cls): return dbSession.query(cls).order_by(-cls.pubDate).first()
def by_province(cls, province): return dbSession.query(cls)\ .filter(SariRecord.provinceName.like('%{}%'.format(province))).all()
def by_uuid(cls, uuid): return dbSession.query(cls).filter(cls.uuid == uuid).first()