Skip to main content

Missing library for working with raw SQL in Python/psycopg

Project description

SlenderQL

SlenderQL - Missing library for working with raw SQL in Python/psycopg

PyPI version

Missing raw SQL tooling for python
  • 💯 No ORM, no magic, just SQL
  • 🎨 Highlighted by default in IDEs
  • 🏜️ DRY up your queries, without losing control
  • 🧐 Pydantic and Psycopg under the hood


Installation

pip install SlenderQL

or

uv add SlenderQL

Usage

from slenderql.repository import Filter, ILike, GTE, LT, BaseRepository, DB
from pydantic import BaseModel
from datetime import datetime


class User(BaseModel):
    name: str
    email: str
    joined_at: datetime


class UserRepository(BaseRepository):
    model = User

    async def all(
        self,
        query: str | None = None,
        after: datetime | None = None,
        before: datetime | None = None,
        limit: int = 100,
        offset: int = 0,
    ) -> list[User]:
        return await self.fetchall(
            """
            SELECT * FROM users
            WHERE ({name} OR {email})
                AND {after}
                AND {before}
            ORDER BY joined_at DESC
            LIMIT %s OFFSET %s
            """,
            (
                ILike("name", query),
                ILike("email", query),
                GTE("after", after, "joined_at"),
                LT("before", before, "joined_at"),
                limit,
                offset,
            )
        )


class RepostoryManager(DB):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.users = UserRepository(self)

db = RepostoryManager(
    f"user=postgres "
    f"password=postgres "
    f"host=postgres "
    f"dbname=postgres"
)

now you can use all() method with multiple filters

>>> await db.users.all(query="alex")
>>> await db.users.all(query="alex", after=datetime(2023, 1, 1))
>>> await db.users.all(query="alex", after=datetime(2023, 1, 1), before=datetime(2023, 2, 1))
>>> await db.users.all(before=datetime(2023, 2, 1), limit=10)

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

slenderql-0.1.6.tar.gz (39.7 kB view details)

Uploaded Source

Built Distribution

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

slenderql-0.1.6-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file slenderql-0.1.6.tar.gz.

File metadata

  • Download URL: slenderql-0.1.6.tar.gz
  • Upload date:
  • Size: 39.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for slenderql-0.1.6.tar.gz
Algorithm Hash digest
SHA256 951719f64a307d0c9a4b5fcf06a6fa7017ba7a9f2482f42f96f79e59be59bf9e
MD5 6479c192d7504d32b0f12121a4dd5431
BLAKE2b-256 11e85b4b3b1f7a3cbf760648f883f364ffe2a4e49003db5ec829183ad5f4c6f3

See more details on using hashes here.

Provenance

The following attestation bundles were made for slenderql-0.1.6.tar.gz:

Publisher: publish.yml on hati-health/slender

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file slenderql-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: slenderql-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for slenderql-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 f429f9a03bea61048e896250fdf44775c13306481c20bffeea1eb5adb96ba596
MD5 896b5a506ba8d0119db01baa874bc59d
BLAKE2b-256 18066df7fde508b74e314dc289692cea1f81fc786f997bc29005be02b460ddec

See more details on using hashes here.

Provenance

The following attestation bundles were made for slenderql-0.1.6-py3-none-any.whl:

Publisher: publish.yml on hati-health/slender

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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