diff --git a/duyunpeng b/duyunpeng
new file mode 100644
index 0000000..6e7dc2c
--- /dev/null
+++ b/duyunpeng
@@ -0,0 +1,2442 @@
+
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
+from flask import Flask, request, jsonify
+import sqlite3
+
+app = Flask(__name__)
+
+
+# 数据库连接函数
+def get_db_connection():
+ conn = sqlite3.connect('example.db')
+ conn.row_factory = sqlite3.Row
+ return conn
+
+
+# 创建表
+def create_table():
+ conn = get_db_connection()
+ try:
+ conn.execute('''CREATE TABLE IF NOT EXISTS users
+ (id INTEGER PRIMARY KEY AUTOINCREMENT,
+ name TEXT NOT NULL,
+ age INTEGER NOT NULL)''')
+ conn.commit()
+ finally:
+ conn.close()
+
+
+# 添加用户
+@app.route('/add_user', method='POST')
+def add_user():
+ data = request.get_json()
+ name = data.get('name')
+ age = data.get('age')
+ if not name or not age:
+ return jsonify({"error": "Name and age are required"}), 400
+ conn = get_db_connection()
+ try:
+ conn.execute('INSERT INTO users (name, age) VALUES (?,?)', (name, age))
+ conn.commit()
+ return jsonify({"message": "User added successfully"}), 201
+ finally:
+ conn.close()
+
+
+# 获取所有用户
+@app.route('/get_all_users', method='GET')
+def get_all_users():
+ conn = get_db_connection()
+ try:
+ cursor = conn.execute('SELECT * FROM users')
+ users = []
+ for row in cursor:
+ user = dict(row)
+ users.append(user)
+ return jsonify(users), 200
+ finally:
+ conn.close()
+
+
+if __name__ == '__main__':
+ create_table()
+ app.run(debug=True)
\ No newline at end of file