def insert(param): """插入 [description] Arguments: id int -- 主键 param dict -- [description] return: True | JsonError """ columns = [i for (i, _) in Config.__table__.columns.items()] param = {k: v for k, v in param.items() if k in columns} if 'created_at' in columns: param['created_at'] = utime.timestamp(3) try: obj = Config(**param) Config.session.add(obj) Config.session.commit() return True except Exception as e: Config.session.rollback() SysLogger.error(e) raise JsonError('insert error')
def update(id, param): """更新记录 [description] Arguments: id int -- 主键 param dict -- [description] return: True | JsonError """ columns = [i for (i, _) in UserLevel.__table__.columns.items()] param = {k: v for k, v in param.items() if k in columns} if 'updated_at' in columns: param['updated_at'] = utime.timestamp(3) if not id: raise JsonError('ID 不能为空') try: UserLevel.Update.filter(UserLevel.id == id).update(param) UserLevel.session.commit() return True except Exception as e: UserLevel.session.rollback() SysLogger.error(e) raise JsonError('update error')
def insert(param): """插入 [description] Arguments: id int -- 主键 param dict -- [description] return: True | JsonError """ columns = [i for (i, _) in Advertising.__table__.columns.items()] param = {k:v for k,v in param.items() if k in columns} if 'created_at' in columns: param['created_at'] = utime.timestamp(3) description = param.get('description', '') if len(description) > 255: raise JsonError('Data too long for \'description\'') if 'start_at' in param.keys(): param['start_at'] = param['start_at'] if param['start_at'].isnumeric() else 0 if 'end_at' in param.keys(): param['end_at'] = param['end_at'] if param['end_at'].isnumeric() else 0 try: obj = Advertising(**param) Advertising.session.add(obj) Advertising.session.commit() return True except Exception as e: Advertising.session.rollback() SysLogger.error(e) raise JsonError('insert error')
def update(key, param): """更新记录 [description] Arguments: key string -- 主键 param dict -- [description] return: True | JsonError """ columns = [i for (i, _) in Config.__table__.columns.items()] param = {k: v for k, v in param.items() if k in columns} if 'updated_at' in columns: param['updated_at'] = utime.timestamp(3) if not key: raise JsonError('key 不能为空') try: Config.Update.filter(Config.key == key).update(param) Config.session.commit() return True except Exception as e: Config.session.rollback() SysLogger.error(e) raise JsonError('update error')
def update(id, param): """更新记录 [description] Arguments: id int -- 主键 param dict -- [description] return: True | JsonError """ columns = [i for (i, _) in Goods.__table__.columns.items()] param = {k: v for k, v in param.items() if k in columns} if 'updated_at' in columns: param['updated_at'] = utime.timestamp(3) if not id: raise JsonError('ID 不能为空') if 'thumb' in param.keys(): try: param['thumb'] = json_decode(param['thumb']) except Exception as e: param['thumb'] = {} try: Goods.Update.filter(Goods.id == id).update(param) Goods.session.commit() return True except Exception as e: Goods.session.rollback() SysLogger.error(e) raise JsonError('update error')
def insert(param): """插入 [description] Arguments: id int -- 主键 param dict -- [description] return: True | JsonError """ columns = [i for (i, _) in Goods.__table__.columns.items()] param = {k: v for k, v in param.items() if k in columns} if 'created_at' in columns: param['created_at'] = utime.timestamp(3) if 'thumb' in param.keys(): try: param['thumb'] = json_decode(param['thumb']) except Exception as e: param['thumb'] = {} raise e else: param['thumb'] = {} try: obj = Goods(**param) Goods.session.add(obj) Goods.session.commit() return True except Exception as e: Goods.session.rollback() SysLogger.error(e) raise JsonError('insert error')
def insert(param): """插入 [description] Arguments: id int -- 主键 param dict -- [description] return: True | JsonError """ columns = [i for (i, _) in Article.__table__.columns.items()] param = {k: v for k, v in param.items() if k in columns} if 'created_at' in columns: param['created_at'] = utime.timestamp(3) category_id = param.get('category_id', 0) if not category_id: raise JsonError('文章分类缺失') description = param.get('description', '') if len(description) > 255: raise JsonError('Data too long for \'description\'') try: obj = Article(**param) Article.session.add(obj) Article.session.commit() return True except Exception as e: Article.session.rollback() SysLogger.error(e) raise JsonError('insert error')
def update(id, param): """更新记录 [description] Arguments: id int -- 主键 param dict -- [description] return: True | JsonError """ columns = [i for (i, _) in Advertising.__table__.columns.items()] param = {k:v for k,v in param.items() if k in columns} if 'updated_at' in columns: param['updated_at'] = utime.timestamp(3) if 'start_at' in param.keys(): param['start_at'] = param['start_at'] if param['start_at'].isnumeric() else 0 if 'end_at' in param.keys(): param['end_at'] = param['end_at'] if param['end_at'].isnumeric() else 0 description = param.get('description', '') if len(description) > 255: raise JsonError('Data too long for \'description\'') if not id: raise JsonError('ID 不能为空') try: Advertising.Update.filter(Advertising.id == id).update(param) Advertising.session.commit() return True except Exception as e: Advertising.session.rollback() SysLogger.error(e) raise JsonError('update error')
def update(id, param): """更新记录 [description] Arguments: id int -- 主键 param dict -- [description] return: True | JsonError """ columns = [i for (i, _) in Article.__table__.columns.items()] param = {k: v for k, v in param.items() if k in columns} if 'updated_at' in columns: param['updated_at'] = utime.timestamp(3) description = param.get('description', '') if len(description) > 255: raise JsonError('Data too long for \'description\'') if not id: raise JsonError('ID 不能为空') status = param.get('status', None) category_id = param.get('category_id', 0) if not category_id: raise JsonError('文章分类缺失') try: Article.Update.filter(Article.id == id).update(param) Article.session.commit() return True except Exception as e: Article.session.rollback() SysLogger.error(e) raise JsonError('update error')