A lightweight Non-ORM with a builder pattern for querying a postgres database
Project description
Query Builder
A lightweight wrapper around psycopg2 for creating queries using a builder pattern.
Example Query:
Getting Started
Installation
Using pip
pip install git+https://github.com/MeadowlarkEngineering/query-builder.git#egg=query-builder
Using poetry
poetry add git+https://github.com/MeadowlarkEngineering/query-builder.git
Usage
Select
Select everything from a table.
from query_builder import PostgresConfig, Select
config = PostgresConfig(dbname="blog", user="postgres-username", password="postgres-password)
Select("comments").execute(config)
> [{'id': 1, 'text': "A comment"}]
Add joins, multiple where clauses, offsets, and limits.
s = Select(table_name="posts").\
join(left_table="posts", right_table="authors", left_col="author_id", right_col="id").\
where(table="authors", column="id", operator="=", value=1).\
where_and(table="authors", column="created_at", operator=">", value="2024-01-01").\
where_and(table="authors", column="created_at", operator=">", value="2024-01-01").\
limit(10).\
offset(5).\
order_by("created_at", table="posts")
result = s.execute(config)
Insert data
i = Insert(table_name="posts").values([{"author_id": 1, "body": "this is a post"}]).on_conflict('id', 'update')
result = i.execute(config)
Development
pip3 install --upgrade pip poetry
poetry self add "poetry-dynamic-versioning[plugin]"
poetry install
Unit Testing
Start a postgres database. The tests don't modify the database, but do require an active psycopg2 connection.
docker run -d -e POSTGRES_PASSWORD=postgres -p 5432:5432 postgres
Run the unit tests
poetry run pytest
You may need to set PGUSER, PGDATABASE, and PGPASSWORD environment variables to establish the connection
Copyright 2024 - Meadowlark Engineering
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 sqlark-1.1.1.tar.gz.
File metadata
- Download URL: sqlark-1.1.1.tar.gz
- Upload date:
- Size: 17.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6900c7f440d8864a2294eabbbb420b1babfcf0ccbbda260c275fef70f721b989
|
|
| MD5 |
be2a8f4421a86750bcab302f646c497e
|
|
| BLAKE2b-256 |
9b8109dab68167da3471add5c2b9e4bd94a76f42b949793605ce84e0ef1764ef
|
Provenance
The following attestation bundles were made for sqlark-1.1.1.tar.gz:
Publisher:
pypi.yaml on MeadowlarkEngineering/sqlark
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sqlark-1.1.1.tar.gz -
Subject digest:
6900c7f440d8864a2294eabbbb420b1babfcf0ccbbda260c275fef70f721b989 - Sigstore transparency entry: 898312265
- Sigstore integration time:
-
Permalink:
MeadowlarkEngineering/sqlark@17bd184f821b2564f2c14f071b4b87c04d7f5b76 -
Branch / Tag:
refs/tags/v1.1.1 - Owner: https://github.com/MeadowlarkEngineering
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yaml@17bd184f821b2564f2c14f071b4b87c04d7f5b76 -
Trigger Event:
release
-
Statement type:
File details
Details for the file sqlark-1.1.1-py3-none-any.whl.
File metadata
- Download URL: sqlark-1.1.1-py3-none-any.whl
- Upload date:
- Size: 22.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
21f5fae70b49ddb68a1c6122ee18afbc99ef18290b1f2c8105a68315a6ab39ab
|
|
| MD5 |
266ff4f32c9c64ebcc5916bcff9a8d28
|
|
| BLAKE2b-256 |
17c298731f02e50e6a3da4cf5beb0f73c114cfefef37121d276ae111a74848ca
|
Provenance
The following attestation bundles were made for sqlark-1.1.1-py3-none-any.whl:
Publisher:
pypi.yaml on MeadowlarkEngineering/sqlark
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sqlark-1.1.1-py3-none-any.whl -
Subject digest:
21f5fae70b49ddb68a1c6122ee18afbc99ef18290b1f2c8105a68315a6ab39ab - Sigstore transparency entry: 898312350
- Sigstore integration time:
-
Permalink:
MeadowlarkEngineering/sqlark@17bd184f821b2564f2c14f071b4b87c04d7f5b76 -
Branch / Tag:
refs/tags/v1.1.1 - Owner: https://github.com/MeadowlarkEngineering
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yaml@17bd184f821b2564f2c14f071b4b87c04d7f5b76 -
Trigger Event:
release
-
Statement type: