Skip to main content

Static Badge Static Badge Static Badge MIT license

GitHub contributors GitHub issues

GitHub stars

AioEasySqlite
Easier aiosqlite version

AioEasySqlite

License: MIT

Example usage (short)

import asyncio
from aioeasysqlite import Db


async def main():
    db = Db("test.db")

    await db.new_table(name="users")
    await db.add_column("users", "id", "INTEGER", primary_key=True, autoincrement=True)
    await db.add_column("users", "name", "TEXT", not_null=True)
    await db.add_column("users", "balance", "REAL", default=0)

    await db.add_row("users", [("name", "John")])
    await db.add_row("users", [("name", "Jane")])

    rows = await db.get_table("users")
    print(rows)
    # OUTPUT: [{'id': 1, 'name': 'John', 'balance': 0.0}, {'id': 2, 'name': 'Jane', 'balance': 0.0}]

    await db.edit_row("users", [("name", "John")], [("balance", 100)])
    row = await db.get_row("users", [("name", "John")])
    print(row)
    # OUTPUT: {'id': 1, 'name': 'John', 'balance': 100.0}

    await db.delete_row("users", [("name", "Jane")])

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

IMPORTANT NOTE!

  • To retrieve old data from database use async load_data method (await db.load_data()).

Example usage (full)

import asyncio
from aioeasysqlite import Db


async def main():
    db = Db("test.db")

    # Creates a new table named "users"
    await db.new_table(name="users")

    # Adds columns to the "users" table
    await db.add_column("users", "id", "INTEGER", primary_key=True, autoincrement=True)
    await db.add_column("users", "name", "TEXT", not_null=True)
    await db.add_column("users", "email", "TEXT", unique=True)
    await db.add_column("users", "balance", "REAL", default=0)

    # Adds rows to the "users" table
    await db.add_row("users", [("name", "John"), ("email", "john@example.com")])
    await db.add_row("users", [("name", "Jane"), ("email", "jane@example.com")])
    await db.add_row("users", [("name", "Bob"), ("email", "bob@example.com")])

    # Gets all rows from the "users" table
    all_users = await db.get_table("users")
    print("All users:", all_users)

    # Gets row where name is "John"
    john = await db.get_row("users", [("name", "John")])
    print("John:", john)

    # Gets multiple rows where balance is 0
    zero_balance = await db.get_rows("users", [("balance", 0)])
    print("Zero balance users:", zero_balance)

    # Gets column with indices
    names = await db.get_column("users", "name", "IND")
    print("Names:", names)

    # Gets column with primary key
    names_pk = await db.get_column("users", "name", "PK")
    print("Names with PK:", names_pk)

    # Edits one row (first match)
    await db.edit_row("users", [("name", "John")], [("balance", 100)])
    john_updated = await db.get_row("users", [("name", "John")])
    print("John updated:", john_updated)

    # Edits multiple rows at once
    await db.edit_rows("users", [("balance", 0)], [("balance", 50)])
    all_users = await db.get_table("users")
    print("All users after edit_rows:", all_users)

    # Deletes one row (first match)
    await db.delete_row("users", [("name", "Bob")])
    all_users = await db.get_table("users")
    print("All users after delete_row:", all_users)

    # Deletes multiple rows
    await db.delete_rows("users", [("balance", 50)])
    all_users = await db.get_table("users")
    print("All users after delete_rows:", all_users)

    # Renames the "users" table to "clients"
    await db.edit_table("users", "clients")
    print("Tables:", list(db.tables.keys()))

    # Deletes the "email" column from the "clients" table
    await db.delete_column("clients", "email")
    client = await db.get_row("clients", [("name", "John")])
    print("Client without email:", client)

    # Deletes the "clients" table
    await db.delete_table("clients")
    print("Tables after delete:", db.tables)

    # Loads existing data from database
    db2 = Db("test.db")
    await db2.load_data()
    print("Loaded tables:", list(db2.tables.keys()))

    # Clears the entire database
    await db2.clear_database()
    print("Database cleared")

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

Donate

If you enjoy using my library, you can support me by donating.

  • UQB-7m2USzQ451d9orgD4iECLD0FL_BV-zzk3i--bdRl51ho - TON
  • TUbvCEDE5wpVRsbLmuU8JfkWY4gNcBNbrx - USDT TRC20

Key Features

  • Easy: Makes working with aiosqlite much easier. No need to know SQL query language anymore.
  • Type-hinted: Types and methods are all type-hinted, enabling excellent editor support.
  • Async: Particularly asynchronus.

Installing

pip3 install aioeasysqlite

Metadata

Release files for aioeasysqlite 1.2.1

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

Source distribution (sdist)

Source distribution for aioeasysqlite 1.2.1
File Size Uploaded Provenance Actions
aioeasysqlite-1.2.1.tar.gz 13.4 kB Without provenance Details for aioeasysqlite-1.2.1.tar.gz

Built distribution (wheel)

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

Total release size: 25.3 kB

Release files / aioeasysqlite-1.2.1.tar.gz

Download URL aioeasysqlite-1.2.1.tar.gz
Size 13.4 kB
Tags Source
SHA-256 checksum
How to use checksums
6cd56bae9f82ca023e087c56950130fd2e67a13e55b52eea2a45740b018a8e85
BLAKE2b-256 checksum
How to use checksums
9e85daeafaa181f7322365b335773ef2ffa502391792cf01251cbfd3a7b321cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.7

Release files / aioeasysqlite-1.2.1-py3-none-any.whl

Download URL aioeasysqlite-1.2.1-py3-none-any.whl
Size 11.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bab0844c94279394d304d8b494bdd8dab8e60cf437bce7ee94ef0db52ab4062e
BLAKE2b-256 checksum
How to use checksums
e238dcd4701416e1c343b8ccb196e14fbd546edfe2b008f861ada67b3255ccba
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.7

Security for aioeasysqlite 1.2.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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