Tornado asynchronous MySQL Driver
Project description
TorMySQL
Tornado asynchronous MySQL Driver.
PyPI page: https://pypi.python.org/pypi/tormysql
About
tormysql - presents a Tornado Future-based API and greenlet for non-blocking access to MySQL.
Installation
pip install TorMySQL
Examples
example pool
from tornado.ioloop import IOLoop from tornado import gen import tormysql pool = tormysql.ConnectionPool( max_connections = 20, #max open connections idle_seconds = 7200, #conntion idle timeout time, 0 is not timeout wait_connection_timeout = 3, #wait connection timeout host = "127.0.0.1", user = "root", passwd = "TEST", db = "test", charset = "utf8" ) @gen.coroutine def test(): with (yield pool.Connection()) as conn: try: with conn.cursor() as cursor: yield cursor.execute("INSERT INTO test(id) VALUES(1)") except: yield conn.rollback() else: yield conn.commit() with conn.cursor() as cursor: yield cursor.execute("SELECT * FROM test") datas = cursor.fetchall() print datas yield pool.close() ioloop = IOLoop.instance() ioloop.run_sync(test)
example helpers
from tornado.ioloop import IOLoop from tornado import gen import tormysql pool = tormysql.helpers.ConnectionPool( max_connections = 20, #max open connections idle_seconds = 7200, #conntion idle timeout time, 0 is not timeout wait_connection_timeout = 3, #wait connection timeout host = "127.0.0.1", user = "root", passwd = "TEST", db = "test", charset = "utf8" ) @gen.coroutine def test(): tx = yield pool.begin() try: yield tx.execute("INSERT INTO test(id) VALUES(1)") except: yield tx.rollback() else: yield tx.commit() cursor = yield pool.execute("SELECT * FROM test") datas = cursor.fetchall() print datas yield pool.close() ioloop = IOLoop.instance() ioloop.run_sync(test)
License
TorMySQL uses the MIT license, see LICENSE file for the details.
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
tormysql-0.3.5.tar.gz
(10.3 kB
view hashes)
Built Distribution
Close
Hashes for tormysql-0.3.5-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a09664f0f79b418a50954c7f34044f24d28d460640079acce73c4c0f5b23332a |
|
MD5 | d4a5bc4adc46c51b5b27f2ead0e8cd49 |
|
BLAKE2b-256 | 230f326df998592f1572a33df1bbb7be221887dde2699b291032a7f688552f27 |