Skip to main content

asyncio db query generator

Project description

aql

simple query generator for modern python

build status code coverage version license code style

Highlights

aql is a simple, modern, and composable query builder, with support for asynchronous execution of queries against multiple database backends using a unified API. aql uses modern, type annotated data structures for both table definitions and queries.

Define tables:

@table("objects")
class Object:
    id: PrimaryKey[AutoIncrement[int]]
    name: Unique[str]
    description: text
    created: datetime

Build queries:

query = (
    Object.select()
    .where(Object.id >= 25)
    .order_by(Object.name)
    .limit(5)
)

sql, params = SqlEngine.prepare(query)
# "select * from `objects` where `id` >= ? order by `name` asc limit 5", (25)

Execute queries:

async with connect(...) as db:
    cursor = db.execute(Object.select().where(Object.id < 100))
    async for row in cursor:
        print(f"{row.id} {row.name} {row.description}")

Simple actions:

async with connect(...) as db:
    rows = await db.get(Object, Object.id == 100)
    rows[0].description += "updated"

    await db.modify(Object, rows)

License

aql is copyright John Reese, and licensed under the MIT license. I am providing code in this repository to you under an open source license. This is my personal repository; the license you receive to my code is from me and not from my employer. See the LICENSE file for 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

aql-0.3.0.tar.gz (28.0 kB view details)

Uploaded Source

Built Distribution

aql-0.3.0-py3-none-any.whl (27.7 kB view details)

Uploaded Python 3

File details

Details for the file aql-0.3.0.tar.gz.

File metadata

  • Download URL: aql-0.3.0.tar.gz
  • Upload date:
  • Size: 28.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.24.0

File hashes

Hashes for aql-0.3.0.tar.gz
Algorithm Hash digest
SHA256 73f23b0b21394a526f0cf84978edd8b581d3ba5d8232949466cc822a71e42ca4
MD5 958fc37ed80b49c9b0ac33780da61c5e
BLAKE2b-256 301101cde67eac39df9a5829e916f5d9d8cdd83f3311edce27c202730628bab4

See more details on using hashes here.

File details

Details for the file aql-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: aql-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 27.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.24.0

File hashes

Hashes for aql-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e2eba3a63cb429bdf1eedc93d567c2ab3cc72ac23182b2b349555cdc31cf7880
MD5 92912a27af6d6303322bc59bc1ac29fd
BLAKE2b-256 98e85ca27b511144f35c7e2e1378b31be0f4414883a74649f97530a9c8ae34d8

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