Wrapper for mysql.connector.python to get a pool of mysql connections
Project description
flask_mysqlpool
This package allows you to use mysql-connector-pythons pooling feature from flask
Usage
import mysql.connector
from flask import Flask, abort, jsonify
from flask_mysqlpool import MySQLPool
app = Flask(__name__)
app.config['MYSQL_HOST'] = 'localhost'
app.config['MYSQL_PORT'] = 3306
app.config['MYSQL_USER'] = 'test'
app.config['MYSQL_PASS'] = 'test'
app.config['MYSQL_DB'] = 'world_x'
app.config['MYSQL_POOL_NAME'] = 'mysql_pool'
app.config['MYSQL_POOL_SIZE'] = 5
app.config['MYSQL_AUTOCOMMIT'] = True
db = MySQLPool(app)
@app.route('/')
def index():
try:
conn = db.connection.get_connection() # get connection from pool
cursor = conn.cursor(dictionary=True)
cursor.execute("select * from world_x.city limit 10", )
result = cursor.fetchall()
conn.close() # return connection to pool
return jsonify(result)
except mysql.connector.ProgrammingError as err:
print(err)
abort(500)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
flask_mysqlpool-1.0.5.tar.gz
(3.3 kB
view details)
Built Distribution
File details
Details for the file flask_mysqlpool-1.0.5.tar.gz
.
File metadata
- Download URL: flask_mysqlpool-1.0.5.tar.gz
- Upload date:
- Size: 3.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5cfb3c7603034cc2fa0ecc564f71232751cb10ef3081bf8f238c25486b3700c8 |
|
MD5 | 3f63027d9d43ce95843bc9fdc4bf4bdb |
|
BLAKE2b-256 | 9411863f16c4835dc25309cc8c9ef4b6340a92c8f513f38dbe08b8622bf9f90d |
File details
Details for the file flask_mysqlpool-1.0.5-py3-none-any.whl
.
File metadata
- Download URL: flask_mysqlpool-1.0.5-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92dd9cc01c5dde6c46edcb5fa2b1086cc3de91ff008e77728ce1ec9d8102825f |
|
MD5 | 37d78ecb4a4de445d1cdb7e54af91244 |
|
BLAKE2b-256 | ee5f9d53030261f842a11b631d26cc673344d1d254cd4092660e3630504fde25 |