Skip to main content

Tornado asynchronous MySQL Driver

Project description

TorMySQL

Build Status

The highest performance asynchronous MySQL driver.

PyPI page: https://pypi.python.org/pypi/tormysql

About

Presents a Future-based API and greenlet for non-blocking access to MySQL.

Support both tornado and asyncio.

Installation

pip install TorMySQL

Used Tornado

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)

Used asyncio alone

example pool

from asyncio import events
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"
)

async def test():
   async with await pool.Connection() as conn:
       try:
           async with conn.cursor() as cursor:
               await cursor.execute("INSERT INTO test(id) VALUES(1)")
       except:
           await conn.rollback()
       else:
           await conn.commit()

       async with conn.cursor() as cursor:
           await cursor.execute("SELECT * FROM test")
           datas = cursor.fetchall()

   print(datas)

   await pool.close()

ioloop = events.get_event_loop()
ioloop.run_until_complete(test)

example helpers

from asyncio import events
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"
)

async def test():
   async with await pool.begin() as tx:
       await tx.execute("INSERT INTO test(id) VALUES(1)")

   cursor = await pool.execute("SELECT * FROM test")
   datas = cursor.fetchall()

   print(datas)

   await pool.close()

ioloop = events.get_event_loop()
ioloop.run_until_complete(test)

Resources

You can read PyMySQL Documentation online for more information.

License

TorMySQL uses the MIT license, see LICENSE file for the details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

zoom-tormysql-0.4.2.tar.gz (14.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

zoom_tormysql-0.4.2-py2.py3-none-any.whl (18.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file zoom-tormysql-0.4.2.tar.gz.

File metadata

  • Download URL: zoom-tormysql-0.4.2.tar.gz
  • Upload date:
  • Size: 14.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.5

File hashes

Hashes for zoom-tormysql-0.4.2.tar.gz
Algorithm Hash digest
SHA256 6125aa52227fab2ea918ef5607dd655d1fddaaafbba191a17b81b9c7f81e9702
MD5 8ac3305b9f6a317efc84a9fe53314fae
BLAKE2b-256 f80ff3aeb300c2465fdde054259a6ec7684fa12b3793e6c9f2db3331f3a2fed6

See more details on using hashes here.

File details

Details for the file zoom_tormysql-0.4.2-py2.py3-none-any.whl.

File metadata

  • Download URL: zoom_tormysql-0.4.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 18.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/2.7.5

File hashes

Hashes for zoom_tormysql-0.4.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 8211f2c94c6a50b64b9a40b7710c508ccb1849a485ea788b785d95c805709552
MD5 0b59e0962b1515fa201418523934bc27
BLAKE2b-256 aacfe9d6a892d5a9491053e9b0e5bac25f14f749d266bd286576a38806b8bca8

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page