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.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e5123f5c06ad4f0a58c1c3a9e48e036fb4f1b4b0bf5d99219467484b4628302 |
|
MD5 | 1fd7fc9ca78c64eb8dc97bddb16b6c0f |
|
BLAKE2b-256 | 3cda54bd999cc63c2e6dd08a68383a95eb2a3891094fe252843e0d907290e940 |
Close
Hashes for mysql_context_manager-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e34c8af997ae5f83b2aae91642cccac040fb21c8de215e7e7daab897da32920d |
|
MD5 | 7cccacab186ab1f60403b5c19e1b5d6b |
|
BLAKE2b-256 | 0970b6fa94dff0f64cea772078818eec42dbf323d789bcd884486d1d91132561 |