def update_by_data(records, update_data, do_commit=True): update_data['update_time'] = datetime.now() records.update(update_data) resp = [True, '', const.code_success] if do_commit: resp = db_commit() return resp
def add_by_data(table, data, do_commit=True): record = table(**data) db.session.add(record) resp = [True, '', const.code_success] if do_commit: resp = db_commit() return resp
def update_by_data(records, update_data, do_commit=True): update_data['update_time'] = datetime.now() records.update(update_data) resp = [True, '', const.CODE_SUCCESS] if do_commit: resp = db_commit() return resp
def add_by_data(table, data, do_commit=True): record = table(**data) db.session.add(record) resp = [True, '', const.CODE_SUCCESS] if do_commit: resp = db_commit() return resp
def delete_by_id(table, id, do_commit=True): res = is_id_exist(table, id) if res[0]: delete_info['update_time'] = datetime.now() res[1].update(delete_info) resp = [True, '', const.code_success] if do_commit: resp = db_commit() return resp return False, '记录不存在', const.code_param_illegal
def delete_by_id(table, id, do_commit=True): res = is_id_exist(table, id) if res[0]: delete_info['update_time'] = datetime.now() res[1].update(delete_info) resp = [True, '', const.CODE_SUCCESS] if do_commit: resp = db_commit() return resp return False, '记录不存在', const.PARAM_ILLEGAL
def after_request(response): from models import db_commit, db_end db_commit() db_end() return response