Skip to main content

A seriazable object for SQLModel queries

Project description

SQLModel Query Builder

A serializable object for simple SQLModel queries.

Why this exists

SQLModel is an Object Relation Mapper (ORM) library that provides great abstractions for interacting with relational databases, such as PostgreSQL and SQLite, via Python. SQLModel gives its users the option to write queries using its own "pythonic" functions, which is safer and easier (in my opinion) than writing raw SQL. Here's what an SQLModel looks like:

with Session(engine) as session:
    statement = select(Hero, Team).join(Team).where(Team.name == "Preventers")
    results = session.exec(statement)

In this example, from SQLModel's own documentation, the words Hero and Team are classes that represent tables in the database.

As convenient as it is, this approach to writing queries has a major drawback: there is no built-in to serialize SQLModel queries. The implication is that you cannot easily dump them into a JSON object that can be sent and received in a REST API, which is a major usecase when developing database applications.

Thus, sqlmodel-query-builder exists to close (or at least narrow) this gap by providing a serializable object for SQLModel queries. For now, it only supports simple queries that involve only SELECT, JOIN, and WHERE statements.

License

This work is licensed under the terms of the GPLv3.

Copyright

© 2024 Brazilian Center for Research in Energy and Materials (CNPEM)

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

sqlmodel_query_builder-0.1.0.tar.gz (2.6 kB view details)

Uploaded Source

Built Distribution

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

sqlmodel_query_builder-0.1.0-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sqlmodel_query_builder-0.1.0.tar.gz
  • Upload date:
  • Size: 2.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.12.8 Linux/6.12.15-200.fc41.x86_64

File hashes

Hashes for sqlmodel_query_builder-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9390e93f15e62db1222b875240ee32e08186093e566d3c5452bfa69128946f33
MD5 b1655bf2ac78f1b1f091cfef27487ab2
BLAKE2b-256 abfa217142af1999ff560e61769ea5dfa8cbe82e10251d7e7dc57b25d8298848

See more details on using hashes here.

File details

Details for the file sqlmodel_query_builder-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: sqlmodel_query_builder-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.12.8 Linux/6.12.15-200.fc41.x86_64

File hashes

Hashes for sqlmodel_query_builder-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e141a53f4cae6fb474f2f77a5ec9cb1e2af3a78d6493eee9d5220c55e0b3350a
MD5 7db91d68c49cadbd245b338fbfff61cc
BLAKE2b-256 e58f64141eb4a55c5c49bdecdefb23cdf35cac31962d580f8cdde7823287e0d1

See more details on using hashes here.

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