Skip to main content

Library for easy work with databases. Easier aiosqlite version.

Project description

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

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

aioeasysqlite-1.2.1.tar.gz (13.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aioeasysqlite-1.2.1-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file aioeasysqlite-1.2.1.tar.gz.

File metadata

  • Download URL: aioeasysqlite-1.2.1.tar.gz
  • Upload date:
  • Size: 13.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for aioeasysqlite-1.2.1.tar.gz
Algorithm Hash digest
SHA256 6cd56bae9f82ca023e087c56950130fd2e67a13e55b52eea2a45740b018a8e85
MD5 2559022d9f485d652175ce28902bad26
BLAKE2b-256 9e85daeafaa181f7322365b335773ef2ffa502391792cf01251cbfd3a7b321cd

See more details on using hashes here.

File details

Details for the file aioeasysqlite-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: aioeasysqlite-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for aioeasysqlite-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bab0844c94279394d304d8b494bdd8dab8e60cf437bce7ee94ef0db52ab4062e
MD5 0b74924a113ead14548b035e51ee29dd
BLAKE2b-256 e238dcd4701416e1c343b8ccb196e14fbd546edfe2b008f861ada67b3255ccba

See more details on using hashes here.

Supported by

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