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.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 450ff68dbf8480dca78a6612c54abdc1cfe93b4164294052000cb9ff37e91b91 |
|
MD5 | 1f2c181904c1bd24496547a0d6cc5a0f |
|
BLAKE2b-256 | 3bf627934cbc5b2169ae5c1487dc6e50a4e6c3aaeac3c9d642bb74be3d1fb1bc |
Close
Hashes for mysql_context_manager-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2eae1897b8f84c7262fbb289180f26588ddef2fb66ac9655e726008aceafdf4b |
|
MD5 | c6736e3c02e8d1fef69c1cb47b40426a |
|
BLAKE2b-256 | c2daf6eb64b3f3d76deeb7eabd367608abcdac607f300f20e3699b3e5c9083d9 |