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, but with a few helpers
  • Optimizes work with multiple filters in SELECTs or optional values in UPDATEs
  • Uses only python syntax, so highlighted by default in IDEs

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"
)

users = await db.users.all(query="alex")

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.3.tar.gz (36.0 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.3-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for slenderql-0.1.3.tar.gz
Algorithm Hash digest
SHA256 8f371d01261a72775a527c0e372a2483411661503e9ddd2384955ba475ad71f2
MD5 4fc2145f5b50dcce8e8ef4a791a60037
BLAKE2b-256 ba6070b9767a9a5687b1565ca75966517ad84fd89687799a68bac69b9999984a

See more details on using hashes here.

Provenance

The following attestation bundles were made for slenderql-0.1.3.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.3-py3-none-any.whl.

File metadata

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

File hashes

Hashes for slenderql-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 fca0b86185e9019126c53b3c78bef5dd6473fc10e454bbdcb523632447659e28
MD5 abafac76007cc29f0fa36068c86c449a
BLAKE2b-256 ea059d554617835a3604723c18027ff07d333f7f2a0826a522bf7385a336d5ea

See more details on using hashes here.

Provenance

The following attestation bundles were made for slenderql-0.1.3-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