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
File details
Details for the file mysql_context_manager-0.2.1.tar.gz
.
File metadata
- Download URL: mysql_context_manager-0.2.1.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.12.0 Linux/6.2.0-1012-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b6b4001b4164afb51e6cca5cae2be52aded38bccafb8c611617ffc4ce2a0f5d0 |
|
MD5 | bfc8f4a8c0b309ea367ba77a3a93df2e |
|
BLAKE2b-256 | 98e6833b343a0654472d95f3f98dd564bb31f67f272a219769fad4a8688991d9 |
File details
Details for the file mysql_context_manager-0.2.1-py3-none-any.whl
.
File metadata
- Download URL: mysql_context_manager-0.2.1-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.12.0 Linux/6.2.0-1012-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3be1ae4697862e90517534fd778dbf7f1ebbf70f07aa5327d6e7973445cd7d28 |
|
MD5 | 28ec532ae8d4f4bc1e9907c831a88243 |
|
BLAKE2b-256 | ede2057a6acbcc1d4313c1ccc1643c92ac1dfeda02ae821528b5cefa7ca780e4 |