Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sqlalchemy_builder-0.1.1.tar.gz (37.0 kB view details)

Uploaded Source

Built Distribution

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

sqlalchemy_builder-0.1.1-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

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

Hashes for sqlalchemy_builder-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f74c583f7f4389dd1ff1d3ff56247f7b3805007d01eadf6806e9f8f93a51417a
MD5 33f66ff8c6781f26550e616516c4aa3c
BLAKE2b-256 fa7343609c0db47db15393786b039a28353d44bc77418a88c5f349be83a0210e

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlalchemy_builder-0.1.1.tar.gz:

Publisher: python-publish.yml on Jamie-Chang/sqlalchemy-builder

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

File details

Details for the file sqlalchemy_builder-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for sqlalchemy_builder-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0ca0e3a2015ecaefcfeb13a884e310b210a43a83c3a5a20f3f2af854c078ddf3
MD5 41ac5cd93064d8723ae8329500862db1
BLAKE2b-256 33935c5c684465cfceea49526f2422a0b8c313a4876f62e04c4af36a2f606cd8

See more details on using hashes here.

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

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