Skip to main content

A handy way to interact with an SQLite database from Python

Project description

Litequery

Litequery is a minimalist, async-first library for interacting with SQLite in Python. It lets you define your queries once and call them as methods. No ORM bloat, just raw SQL power.

Why Litequery?

  • Simplicity: Define SQL queries in .sql files. No complex ORM layers.
  • Async first: Built for modern async Python with aiosqlite.
  • Flexible: Supports different SQL operations seamlessly.

Installation

pip install litequery

Getting Started

Define Your Queries

Create a queries.sql file. Name your queries using comments and write them in pure SQL.

-- name: get_all_users
SELECT * FROM users;

-- name: get_user_by_id^
SELECT * FROM users WHERE id = :id;

-- name: get_last_user_id$
SELECT MAX(id) FROM users;

-- name: insert_user<!
INSERT INTO users (name, email) VALUES (:name, :email);

-- name: delete_all_users!
DELETE FROM users;

Using Your Queries

Define your database and queries, and then call them as methods. It's as straightforward as it sounds.

import litequery
import asyncio

async def main():
    lq = litequery.setup("database.db", "queries.sql")
    await lq.connect()

    user_id = await lq.insert_user(name="Alice", email="alice@example.com")
    print(user_id)

    users = await lq.get_all_users()
    print(users)

    user = await lq.get_user_by_id(id=user_id)
    print(user)

    rows_count = await lq.delete_all_users()

    await lq.disconnect()


asyncio.run(main())

Wrapping Up

Litequery is all about simplicity and efficiency. Why wrestle with bloated ORMs when you can have raw SQL power? If you think there's a better way or have suggestions, let's hear them. Happy querying!

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

litequery-0.1.0.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

litequery-0.1.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: litequery-0.1.0.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for litequery-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4db8dd2c153cb42a6152f6cfaffbd9daaa6f474adba12836683bf297427b418c
MD5 ed1859a04984d31c5721a226429abe87
BLAKE2b-256 e800e767cf0f71cea198dd91c7c050ed5c7973ec62422415a2b25f625124af22

See more details on using hashes here.

File details

Details for the file litequery-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: litequery-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for litequery-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f915f104ab71a75ad2983b0a25807b21b0e200d53e6335637242a42ef78f09fe
MD5 d35db7c55ed6b0574e732ad6bb2319a9
BLAKE2b-256 6e9d7770ab22f39ced7effbbe9537e5e02eeeceb597ec44fdc1e78f226ffcb4a

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