def get_books(): query = request.json #默认值判断 index = query['pageIndex'] size = query['pageSize'] if 'filter' not in query: rows = dbconn.fetch_rows(table=table_name, limit=','.join( [str((index - 1) * size), str(size)])) return jsonify( back_res({ "rows": rows, "total": dbconn.count(table=table_name) })) else: filter = query['filter'] order = filter.pop('order') rows = dbconn.fetch_rows(table=table_name, condition=filter, order=order, limit=','.join( [str((index - 1) * size), str(size)])) return jsonify( back_res({ "rows": rows, "total": dbconn.count(table=table_name, condition=filter) }))
def get_task(): query = request.args if not query or 'id' not in query: rows = dbconn.fetch_rows(table='js_books', limit='0,5') return jsonify(rows) else: task_id = request.args['id'] task = list(filter(lambda t: t['id'] == int(task_id), tasks)) return jsonify(back_res(200, task, '成功')) if task else jsonify( back_res())
def upt_books(): query = request.json rows = dbconn.update(table=table_name, data=query['data'], condition=query['condition']) return jsonify(back_res(rows))
def add_books(): query = request.json # if not query or 'title' not in query or 'code' not in query: # abort(400) last_id = dbconn.insert(table=table_name, data=query) return jsonify(back_res(last_id))
def add_task(): query = request.json if not query or 'id' not in query or 'info' not in query: abort(400) task = {'id': query['id'], 'info': query['info']} tasks.append(task) return jsonify(back_res(200, 1, '成功'))
def del_books(): query = request.json rows = dbconn.delete(table=table_name, condition=query, limit='1') return jsonify(back_res(rows))