Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # sqlwitch tries to give you just the right amount of abstraction for fast MySQL-based web applications.
- # Avoid complex and memory hungry ORM libraries while keeping your code easy to maintain:
- def get_db_handler(db_auth):
- conn = MySQLdb.connect(**db_auth)
- cursor = conn.cursor(MySQLdb.cursors.DictCursor)
- conn.set_character_set('utf8')
- cursor.execute('set names utf8;')
- cursor.execute('set character_set_connection = utf8;')
- return sqlwitch(cursor, conn)
- @app.route('/-/users', methods=['POST'])
- def new_user():
- db = get_db_handler(config.db)
- with db.select('user_id', from_='users'):
- db.where('email = %s', request.form['email'])
- existing_user = db.fetchone()
- if existing_user:
- return jsonify(status=1, message='user_exists')
- user_id = new_user_id(db)
- with db.insert(into='users') as obj:
- obj.user_id = user_id
- obj.email = request.form['email']
- obj.password = request.form['password']
- db.execute()
- db.connection.commit()
- return jsonify(
- status=0,
- user_id=user_id,
- email=request.form['email']
- )
Add Comment
Please, Sign In to add comment