Work with MySQL databases asynchronously, and in context.
Project description
MySQL Context Manager
Work with MySQL based databases asynchronously, using a context manager.
Getting started
You can get mysql-context-manager
from PyPI,
which means you can install it with pip easily:
python -m pip install mysql-context-manager
Example
from mysql_context_manager import MysqlConnector
async with MysqlConnector(hostname="localhost") as conn:
results = await conn.query("select username from users where is_bender = 1 order by username asc;")
assert results[0]["username"] == "Aang"
assert results[1]["username"] == "Katara"
assert results[2]["username"] == "Toph"
Example using SQLAlchemy
from mysql_context_manager import MysqlConnector
import sqlalchemy
from sqlalchemy.dialects import mysql
metadata = sqlalchemy.MetaData()
users = sqlalchemy.Table(
"users",
metadata,
sqlalchemy.Column("user_id", mysql.INTEGER(), autoincrement=True, nullable=False),
sqlalchemy.Column("username", mysql.VARCHAR(length=128), nullable=False),
sqlalchemy.Column("is_bender", mysql.SMALLINT(), autoincrement=False, nullable=True),
sqlalchemy.PrimaryKeyConstraint("user_id"),
mysql_default_charset="utf8mb4",
mysql_engine="InnoDB",
)
async with MysqlConnector(hostname="localhost") as conn:
results = await conn.query(users.select().where(users.c.username == "Aang"))
assert results[0]["username"] == "Aang"
assert results[0]["is_bender"] == 1
Changelog
Refer to the CHANGELOG.rst file.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for mysql-context-manager-0.1.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 375a8233611e570c81d93d6bdc3670a00a52ceb46c4b15068b4d434d2f32fbe0 |
|
MD5 | 253559e4dae402e5dc5edf4a5e94d6da |
|
BLAKE2b-256 | 79d5b23b8e0d7f5686a9c2b708ae39f31f083d63336c223fb3e240c76118e4c9 |
Close
Hashes for mysql_context_manager-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ebd6d47b54777eefe99b97bea42ac406afa8a8a8d68d173b4661c8b7c32202e |
|
MD5 | 517feda87d8218e01667b270e30f51bd |
|
BLAKE2b-256 | 536cced8435ffbaac020e02584fc3b24eae75ecc9e1a1e95ff0cdb289e8b7ae6 |