Build SQLAlchemy statements avoiding common footguns.
Project description
sqlalchemy-builder
Build SQLAlchemy statements avoiding common footguns.
Example
Build select statements functionally using | and |=
select(Model).where(Model.id == 1)
Becomes:
from sqlalchemy_builder.select import where
select(Model) | where(Model.id == 1)
|= is also supported:
statement = select(Model)
if value:
statement |= where(Model.value == value)
Why?
There is a common mistake when building sqlalchemy statements.
statement = select(Model)
if status is not None:
statement.where(Model.status == status)
The statement.where does not do anything as it generates a new Select object.
To fix this we have to assign it:
statement = statement.where(...)
This can be a bit verbose though not the worst issue. By using implace |= we can avoid this issue without making the statement mutable.
It's also just a fun syntax to play with.
Development
Installing dependencies:
$ uv sync
Running tests:
$ uv run pytest
Project details
Release history Release notifications | RSS feed
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 sqlalchemy_builder-0.1.1.tar.gz.
File metadata
- Download URL: sqlalchemy_builder-0.1.1.tar.gz
- Upload date:
- Size: 37.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f74c583f7f4389dd1ff1d3ff56247f7b3805007d01eadf6806e9f8f93a51417a
|
|
| MD5 |
33f66ff8c6781f26550e616516c4aa3c
|
|
| BLAKE2b-256 |
fa7343609c0db47db15393786b039a28353d44bc77418a88c5f349be83a0210e
|
Provenance
The following attestation bundles were made for sqlalchemy_builder-0.1.1.tar.gz:
Publisher:
python-publish.yml on Jamie-Chang/sqlalchemy-builder
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sqlalchemy_builder-0.1.1.tar.gz -
Subject digest:
f74c583f7f4389dd1ff1d3ff56247f7b3805007d01eadf6806e9f8f93a51417a - Sigstore transparency entry: 168181231
- Sigstore integration time:
-
Permalink:
Jamie-Chang/sqlalchemy-builder@db0833c626339e055c76bbed5c301d71623f1167 -
Branch / Tag:
refs/tags/0.1.1 - Owner: https://github.com/Jamie-Chang
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@db0833c626339e055c76bbed5c301d71623f1167 -
Trigger Event:
release
-
Statement type:
File details
Details for the file sqlalchemy_builder-0.1.1-py3-none-any.whl.
File metadata
- Download URL: sqlalchemy_builder-0.1.1-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ca0e3a2015ecaefcfeb13a884e310b210a43a83c3a5a20f3f2af854c078ddf3
|
|
| MD5 |
41ac5cd93064d8723ae8329500862db1
|
|
| BLAKE2b-256 |
33935c5c684465cfceea49526f2422a0b8c313a4876f62e04c4af36a2f606cd8
|
Provenance
The following attestation bundles were made for sqlalchemy_builder-0.1.1-py3-none-any.whl:
Publisher:
python-publish.yml on Jamie-Chang/sqlalchemy-builder
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sqlalchemy_builder-0.1.1-py3-none-any.whl -
Subject digest:
0ca0e3a2015ecaefcfeb13a884e310b210a43a83c3a5a20f3f2af854c078ddf3 - Sigstore transparency entry: 168181232
- Sigstore integration time:
-
Permalink:
Jamie-Chang/sqlalchemy-builder@db0833c626339e055c76bbed5c301d71623f1167 -
Branch / Tag:
refs/tags/0.1.1 - Owner: https://github.com/Jamie-Chang
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@db0833c626339e055c76bbed5c301d71623f1167 -
Trigger Event:
release
-
Statement type: