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.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d61cff1b6a4666cd9b814f0023941ec00430ed6777d62cef57e1cc8e6924b1cc |
|
MD5 | 7407410e163a3bf683f17067316cfc4b |
|
BLAKE2b-256 | d17b39cb862d26532b736120f3d1a646b7139c1c73a58879e578e5a8855e739b |
Close
Hashes for mysql_context_manager-0.1.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 39abfb5ff84932cfccc32c4ff4482f980750aaf92bfd29bba8338b190e9b9806 |
|
MD5 | dec84d47baabea3410533a05107c799d |
|
BLAKE2b-256 | 2cc486804e4939ac8eb529c09a483d31074195f941d4f2bf6b1e0474dd0a0c81 |