def add(img: str, name: str = '', title: str = '', receive_text: str = None, custom_style: str = None): uuid = shortuuid.uuid() coupon = { 'uuid': uuid, 'name': name, 'img': img, 'title': title, 'receive_text': receive_text, 'custom_style': custom_style } db.execute(Coupon.insert().values(**coupon)) return uuid
def add(cid: int, tel: str): coupon_res = coupon.get_by_id(cid) if not coupon_res: raise error.CouponNotFoundError(cid) telephone = {'tel': tel, 'coupon_id': cid} result = db.execute(Telephone.insert().values(**telephone)) return result.inserted_primary_key
def inc_submit(cid: str, value: int = 1): exp = Coupon.update().values( submit_count=Coupon.c.submit_count.op('+')(value)).where( Coupon.c.uuid == cid) result = db.execute(exp) view = result.last_updated_params() result.close() return view
def get_all(): exp = select([Coupon]) result = db.execute(exp) coupons = result.fetchall() result.close() return coupons
def get_by_uuid(uuid: str): exp = select([Coupon]).where(Coupon.c.uuid == uuid) result = db.execute(exp) coupon = result.fetchone() result.close() return coupon
def get_by_id(cid: int): exp = select([Coupon]).where(Coupon.c.id == cid) result = db.execute(exp) coupon = result.fetchone() result.close() return coupon
def edit(cid: str, **kwargs): db.execute(Coupon.update().values(**kwargs).where(cid == Coupon.c.uuid)) return cid