Skip to main content

asynchronous tornado database connection

Project description

torndb rewrite to asynchronous

Example

First get a connection object

from aiotorndb import Connection

conn = Connection(
    host="127.0.0.1",
    db="test",
    user="root",
    password="123456",
    port=3306,
    time_zone="+8:00",
    charset="utf8",
)

Next, you can use methods such as select, update, insert, delete, etc.

import asyncio

async def test():
    get_result = await conn.get("select * from user where id = 1")
    print(get_result)
    # {'id': 1, 'name': 'tom'}

    select_result = await conn.select("select * from user")
    print(select_result)
    # [{'id': 1, 'name': 'tom'}, {'id': 2, 'name': 'ellis'}]

    update_result = await conn.update("update user set name = %(name)s where id = 1", name="eddie")
    print(update_result)
    # 1

    insert_result = await conn.insert("insert into user (name) values (%(name)s)", name="dav")
    print(insert_result)
    # 3

    # sql = select * from user where id in (1, 3)
    select_result2 = await conn.select("select * from user where id in %(user_ids)s", user_ids=[1, 3])
    print(select_result2)
    # [{'id': 1, 'name': 'eddie'}, {'id': 3, 'name': 'dav'}]

    # sql = select * from project_tag where name like '%e%'
    select_result3 = await conn.select("select * from project_tag where name like %(name)s", name="%e%")
    print(select_result3)
    # [{'id': 1, 'name': 'eddie'}, {'id': 2, 'name': 'ellis'}]

asyncio.run(test())

Project details


Release history Release notifications | RSS feed

This version

0.2

Download files

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

Source Distribution

aiotorndb-0.2.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

aiotorndb-0.2-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

File details

Details for the file aiotorndb-0.2.tar.gz.

File metadata

  • Download URL: aiotorndb-0.2.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for aiotorndb-0.2.tar.gz
Algorithm Hash digest
SHA256 270e8cab9dea75e30c76fb51159fcb9e37e97ac3e955c16879a63ea8282d011b
MD5 b803adcb7cb7af71ccea7f1ce6a3b39f
BLAKE2b-256 69c04f6f0182207439d25d6084ea7c667e4095424444be159185efe352164662

See more details on using hashes here.

File details

Details for the file aiotorndb-0.2-py3-none-any.whl.

File metadata

  • Download URL: aiotorndb-0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.4

File hashes

Hashes for aiotorndb-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a855d83fb8d0bfdf56337ef8549cac7273900dab49a7138ecb302ddd21895f12
MD5 d61467fd4cb0de8d85958db1002221a2
BLAKE2b-256 edccb257e03fb98e2a2f55283476c3a82e0baa60c3007f0a192064de78cbe4ff

See more details on using hashes here.

Supported by

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