示例#1
0
def get_message(id=None,
                send_status=None,
                order_by='id',
                order_type='desc',
                page_num=1,
                page_size=10,
                to_dict=True):
    '''查询数据库message记录'''
    data = Message.select()
    if id:
        data = data.where(Message.id == id, Message.is_deleted == 0).first()
    else:
        if send_status is not None:
            data = data.where(Message.send_status == send_status)

        order_field = getattr(Message, order_by)
        if order_type.lower() == 'desc':
            data = data.where(Message.is_deleted == 0).order_by(-order_field)
        else:
            data = data.where(Message.is_deleted == 0).order_by(+order_field)
        if page_size > 0 and page_num > 0:
            data = data.paginate(page_num, page_size)
    if to_dict:
        if isinstance(data, peewee.SelectQuery):
            data = [model2dict(i) for i in data]
        else:
            data = model2dict(data)
    return data
示例#2
0
def update_message(id, send_status=None, is_deleted=None, to_dict=True):
    data = Message.select().where(Message.id == id).first()
    if not data:
        return
    if send_status is not None:
        data.send_status = send_status
    if is_deleted is not None:
        data.is_deleted = is_deleted
    data.save()
    if to_dict:
        data = model2dict(data)
    return data
示例#3
0
 def get_record(cls,
                id=None,
                order_by='id',
                order_type='desc',
                to_dict=True):
     if id is not None:
         data = cls.select().where(cls.id == id,
                                   cls.is_deleted == 0).first()
     else:
         order_field = getattr(cls, order_by)
         if order_type.lower() == 'asc':
             data = cls.select().where(
                 cls.is_deleted == 0).order_by(-order_field)
         else:
             data = cls.select().where(
                 cls.is_deleted == 0).order_by(+order_field)
     if to_dict:
         if isinstance(data, peewee.SelectQuery):
             data = [model2dict(i) for i in data]
         else:
             data = model2dict(data)
     return data
示例#4
0
 def update_record(cls,
                   id,
                   send_status=None,
                   is_deleted=None,
                   to_dict=True):
     data = cls.select().where(cls.id == id, cls.is_deleted == 0).first()
     if not data:
         return
     if send_status is not None:
         data.send_status = send_status
     if is_deleted is not None:
         data.is_deleted = is_deleted
     data.save()
     if to_dict:
         data = model2dict(data)
     return data
示例#5
0
 def add_record(cls, message, to_dict=True):
     data = cls.create(message=message)
     if to_dict:
         data = model2dict(data)
     return data
示例#6
0
def add_message(message, to_dict=True):
    data = Message.create(message=message)
    if to_dict:
        data = model2dict(data)
    return data