Alternative Queries: Typed and Reusable Handcrafted SQL
Project description
Alternative Queries
Alternative queries is a library created to help with handcrafted SQL queries.
It works by providing a class that represent the queries where its parameter
types are checked by Pydantic.
If you want to write reusable and nested handcrafted SQL queries, you can check more information on the Alternative Queries Documentation. If you want to know how Alternative Queries can help you, check the Why use Alternative Queries? section of the documentation.
Installation
The library is available in the Python Package Index.
pip install altqq
Quick Start
To start, define a class by inheriting the altqq.Query class. The class should
have a query following the python formatting standards. The variable names
inside the __query__ must match the other attributes defined on the class.
import altqq
class SelectUserByFirstName(altqq.Query):
__query__ = """
SELECT * FROM "Users"
WHERE first_name = {first_name}
"""
first_name: str
The class can be used like a dataclass. In fact, classes inheriting the
altqq.Query class are turned into a Pydantic dataclass.
query = SelectUserByFirstName(first_name="arietta")
The object can be converted into a query suitable for a DBMS library of your
choice. For example, calling the altqq.to_pyodbc function will convert the
object to PyODBCQuery which provides the query string and the parameters.
pyodbc_query = altqq.to_pyodbc(query)
print(pyodbc_query.query)
#
# SELECT * FROM "Users"
# WHERE first_name = ?
#
print(pyodbc_query.parameters)
# ['arietta']
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 altqq-0.0.9.tar.gz.
File metadata
- Download URL: altqq-0.0.9.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.12.3 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e25da2b584b86c0bf630a64a85da5b18a2250f4dc0ea05a27d362b0d4de033d4
|
|
| MD5 |
7da2372079c78a3455293ef52d2dd6c6
|
|
| BLAKE2b-256 |
1bac1793f7ff79e0c7d392f59c1bcd400ff94e5bb8494bb78e571082a4d436b0
|
File details
Details for the file altqq-0.0.9-py3-none-any.whl.
File metadata
- Download URL: altqq-0.0.9-py3-none-any.whl
- Upload date:
- Size: 10.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.2.1 CPython/3.12.3 Linux/6.11.0-1018-azure
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
39e9ddf27d5eb6fecaadf1c68bf6a0fdb8077033ac1247336ba1de860fce1ea0
|
|
| MD5 |
482ec9f49ab67caa2aa26d4e9a095b63
|
|
| BLAKE2b-256 |
1ed3f3da6acbc4bd2d8678939bac3a33f559290eb8d67ae21ca9e17c145b57a6
|