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.0.1.tar.gz (2.8 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.0.1-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sqlmodel_query_builder-0.0.1.tar.gz
  • Upload date:
  • Size: 2.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.7 Linux/6.11.6-200.fc40.x86_64

File hashes

Hashes for sqlmodel_query_builder-0.0.1.tar.gz
Algorithm Hash digest
SHA256 6501b002e3b0c7d511a1e38e2647253adcf162cbdf541ef0f09ceb078039c129
MD5 0eb6531e98245590c617c94366924b16
BLAKE2b-256 2efd2436b8ab6c7b601f7fa033e12dced72ffd49a2672359a0f770df7403aa21

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for sqlmodel_query_builder-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0ef08ffb0a18f3711477006b1fa212589cf3c62b9f4204928bf9844936f578a8
MD5 c49ccd7cc96ef7acd6e1e6eb57da70cb
BLAKE2b-256 f3e091abc97eb2a80544a3b6eaee97ac48f1d401eda75505e44d8c8eb1a5074d

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