Skip to main content

Library for easy work with databases. Easier aiosqlite version.

Project description

Static Badge Static Badge Static Badge

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

Future

All 'arg' will be replaced by 'args', so people could work with multiple filtered rows at once.

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.0.tar.gz (13.0 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.0-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aioeasysqlite-1.2.0.tar.gz
  • Upload date:
  • Size: 13.0 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.0.tar.gz
Algorithm Hash digest
SHA256 8cd693cdc71fd0d255a58396af7c63e40f0756739a4a89c2ac7c9900e4778e97
MD5 013b5012f4029ee030cf5e88b0316025
BLAKE2b-256 32471bc4a6f3b13f074c3812ca59a39ac1fe82ef42ec1171ec70ad1200314463

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aioeasysqlite-1.2.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2aa4a1b43b60ec0161b32b15f5738d7a9da954b2a9e0cbce700d2fa68e9116a0
MD5 b63763889471c059c9a14e7054e892f1
BLAKE2b-256 530bced856c36e3a309318d777907277e4d50b95bb316c11241c14c9299db7e3

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