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.0.tar.gz (36.9 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.0-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

Details for the file sqlalchemy_builder-0.1.0.tar.gz.

File metadata

  • Download URL: sqlalchemy_builder-0.1.0.tar.gz
  • Upload date:
  • Size: 36.9 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.0.tar.gz
Algorithm Hash digest
SHA256 e05b47325fd5e999dd01276e3ecce3e15882fbf39494825bdfedd51a2e320bcf
MD5 f1d8af6bb27c546c2ecb53da446982c4
BLAKE2b-256 d63011a9b29ad5ed4b10be24dee247fafedfb7787babe3e13ff17255ce0aacc2

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlalchemy_builder-0.1.0.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.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sqlalchemy_builder-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fe97d5ff0fc2b043706ecac1706cc98771e1a16ab70a8f518de264d556ee4fbf
MD5 16693afe52c1e62eaa8b2f49d9cf947b
BLAKE2b-256 6ffcc2abb48e2c064d70f442004124fe45b1f5efe9b372cb565f683ef24d3319

See more details on using hashes here.

Provenance

The following attestation bundles were made for sqlalchemy_builder-0.1.0-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