Missing library for working with raw SQL in Python/psycopg
Project description
SlenderQL
SlenderQL - Missing library for working with raw SQL in Python/psycopg
- 💯 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file slenderql-0.1.5.tar.gz.
File metadata
- Download URL: slenderql-0.1.5.tar.gz
- Upload date:
- Size: 39.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b54ef1cdb2cc90fb580609e73546bd998187353333d8f0ff62d958e6761b1134
|
|
| MD5 |
61bfd3414f4e40b52ac9eb6183990165
|
|
| BLAKE2b-256 |
f318bcced0c8500603ce18fa632e048d97dfef728c8e3119bb2795ead5a6ba0f
|
Provenance
The following attestation bundles were made for slenderql-0.1.5.tar.gz:
Publisher:
publish.yml on hati-health/slender
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
slenderql-0.1.5.tar.gz -
Subject digest:
b54ef1cdb2cc90fb580609e73546bd998187353333d8f0ff62d958e6761b1134 - Sigstore transparency entry: 464212301
- Sigstore integration time:
-
Permalink:
hati-health/slender@167e40c98e0f9e414cdde442addcccd04993c74f -
Branch / Tag:
refs/tags/v0.1.5 - Owner: https://github.com/hati-health
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@167e40c98e0f9e414cdde442addcccd04993c74f -
Trigger Event:
push
-
Statement type:
File details
Details for the file slenderql-0.1.5-py3-none-any.whl.
File metadata
- Download URL: slenderql-0.1.5-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72787e9cf3320f86f6dc049ed469861ed38d14d476c9e0767a7f12c676bcb7bc
|
|
| MD5 |
a507467f1b20116cb95700957382ab00
|
|
| BLAKE2b-256 |
89cbb7591561cbc46a49a913d015c68c715af4a183eebef53e121cb15afd5dd3
|
Provenance
The following attestation bundles were made for slenderql-0.1.5-py3-none-any.whl:
Publisher:
publish.yml on hati-health/slender
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
slenderql-0.1.5-py3-none-any.whl -
Subject digest:
72787e9cf3320f86f6dc049ed469861ed38d14d476c9e0767a7f12c676bcb7bc - Sigstore transparency entry: 464212337
- Sigstore integration time:
-
Permalink:
hati-health/slender@167e40c98e0f9e414cdde442addcccd04993c74f -
Branch / Tag:
refs/tags/v0.1.5 - Owner: https://github.com/hati-health
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@167e40c98e0f9e414cdde442addcccd04993c74f -
Trigger Event:
push
-
Statement type: