Skip to main content

sqlitei

codecov Quality Gate Status

An opinionated sqlite3 wrapper.

The main goal of this package is simply to have stmt.execute() return bool instead of a cursor object. So that it can be useful to indicate True if the query succeeds, or False otherwise. Empty results on INSERT, UPDATE, DELETE, and SELECT are considered as False.

It adopts the prepare - execute pattern merely for the user experience.

Synchronous usage

from sqlitei import Database

db = Database('example.db')


def main():
    try:
        db.connect(timeout=30)

        stmt = db.prepare(
            'CREATE TABLE IF NOT EXISTS users ('
            '  id INTEGER PRIMARY KEY,'
            '  name TEXT NOT NULL,'
            '  age INTEGER NOT NULL'
            ');'
        )
        stmt.execute()  # True

        stmt = db.prepare('SELECT * FROM users')
        stmt.execute()  # False, no rows yet!

        stmt = db.prepare('SELECT * FROM user')
        stmt.execute()  # False, no such table!

        stmt = db.prepare(
            'INSERT INTO users (name, age) VALUES (?, ?)'
        )
        stmt.execute(['Alice'])  # False
        stmt.execute(['Alice', 30])  # True

        stmt = db.prepare('SELECT * FROM users LIMIT 10')
        stmt.execute()  # True
        row = stmt.fetch()

        while row:
            print('*', row['name'], row['age'])
            row = stmt.fetch()
    finally:
        db.close()

if __name__ == '__main__':
    main()

Asynchronous usage

Asyncronous usage is powered by awaiter.

The following example uses an asynchronous context manager, although the try - finally approach as above can still be used.

import asyncio

from sqlitei import AsyncDatabase


async def main():
    async with AsyncDatabase('example.db') as db:
        stmt = db.prepare(
            'CREATE TABLE IF NOT EXISTS users ('
            '  id INTEGER PRIMARY KEY,'
            '  name TEXT NOT NULL,'
            '  age INTEGER NOT NULL'
            ');'
        )
        await stmt.execute(timeout=30)

        stmt = db.prepare(
            'INSERT INTO users (name, age) VALUES (?, ?)'
        )
        await stmt.execute(['Alice', 30])

        stmt = db.prepare('SELECT * FROM users LIMIT 10')
        await stmt.execute()
        row = await stmt.fetch()

        while row:
            print('*', row['name'], row['age'])
            row = await stmt.fetch()

if __name__ == '__main__':
    asyncio.run(main())

Install

python3 -m pip install --upgrade sqlitei

License

MIT

Release files for sqlitei 0.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sqlitei 0.0.0
File Size Uploaded
sqlitei-0.0.0.tar.gz 4.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sqlitei 0.0.0
File Interpreter ABI Platform
sqlitei-0.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 8.5 kB

Release files / sqlitei-0.0.0.tar.gz

Download URL sqlitei-0.0.0.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
7392e7dbf0ddc4254b64d7c81f2f0f5d48e345071d55c963c2357e6a7c97de6c
BLAKE2b-256 checksum
How to use checksums
829321c7cad3c68ce3876b349b948eeaed567e386a84691b007ab6e213b0fb3f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.9

Release files / sqlitei-0.0.0-py3-none-any.whl

Download URL sqlitei-0.0.0-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d2a9d73c97c53a3a37c0743d62eda92e1816653e0fbda479bd1b3bc0274b6a0e
BLAKE2b-256 checksum
How to use checksums
898a61b6ddf4038619fe928a542989f8777ab1eebef2164efe4db324899df09a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.9

Release history Release notifications | RSS feed

This release

0.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page