Skip to main content

asyncio 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.1.0.tar.gz (15.4 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: aql-0.1.0.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3

File hashes

Hashes for aql-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9d2e9624df53db3b4de78c38a8d673f507030e53e2ffe1cd6a8a9dc0814b587f
MD5 7cfcd28b982ec4638fb2574c94d67cc9
BLAKE2b-256 863e10ba38416241c8f92b0bec42ccc1e34b7c8e4496e52d42a059e6ad7ad68d

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