Human mind friendly SQL generator
Project description
explicit-sql
A human mind friendly SQL generator for DuckDB.
Overview
I genuinely do not like ORMs because of the Object–relational impedance mismatch. While we have many good ORMs that can speed up development of POCs and MVPs drastically, this project aims at a simpler idea: implement a human mind friendly and type-safe SQL generator for all basic operations:
- CREATE TABLE
- DROP TABLE
- INSERT INTO
- SELECT FROM
- UPDATE
- DELETE
- And more...
I found myself developing this when working on simple side-projects using DuckDB and realized there was no interface to generate SQL queries from TypedDict definitions.
Philosophy
The goal is to stay as close to "raw" Python as possible. For table schemas, I chose TypedDict, and besides that have only two classes:
- TableConfig - for configuration settings
- ExplicitTable - a container class for both the TypedDict definition and config
This minimalist approach should be enough to achieve a useful, type-safe SQL generator without the complexity of ORMs.
Requirements
- Python 3.10+
Installation
pip install explicit-sql
Quick Example
from explicit_sql import (
TableDefinition,
TableConfig,
ExplicitTable,
create_table_sql,
insert_sql,
select_sql
)
# Define your table schema
class UsersTable(TableDefinition):
id: int
name: str
is_active: bool | None
users_config = TableConfig(
name="users",
schema="public",
primary_key_name="id",
primary_key_type=int,
)
users_table = ExplicitTable(
config=users_config,
table_definition=UsersTable
)
create_table_sql = create_table_sql(users_table)
print(create_table_sql)
insert_payload: UsersTable = {
"amount": 500,
"name": "John Doe",
"is_active": True,
}
print(insert_sql(users_table, insert_payload))
print(
select_sql(
users_table,
select_columns=["name", "amount"],
where_values={"is_active": True},
order_by=["amount"],
limit=10,
)
)
# Select all columns
print(select_sql(users_table, limit=10))
Roadmap
See the milestone plan for the development roadmap.
License
MIT
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
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 explicit_sql-0.0.5.tar.gz.
File metadata
- Download URL: explicit_sql-0.0.5.tar.gz
- Upload date:
- Size: 12.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
462d3fef3395475e537466c27bd5b8e454343a18627e120eb2e3a542abfb4285
|
|
| MD5 |
5ee2a151df2e91ea8bf87d440a2144c7
|
|
| BLAKE2b-256 |
ac38b850bc843449a661a92d21c8777701c1c2627567784ea37ee366a92ec2a4
|
File details
Details for the file explicit_sql-0.0.5-py3-none-any.whl.
File metadata
- Download URL: explicit_sql-0.0.5-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e953c28d759e569cd38ce456518d2309d1167b16338877cd533debebbcc3b987
|
|
| MD5 |
8e25ef6cd09871cb8bdb3ab61c4e7967
|
|
| BLAKE2b-256 |
0bf5bd0de84154e89d56fcac6d3e7726e9deeee65266cf8948f79244d005ce67
|