DEV Community

Kamyar Inanloo
Kamyar Inanloo

Posted on

I built a tiny Python library that turns method names into SQL queries

I’ve been working on a small library called guess-what. The idea is simple: instead of writing boilerplate CRUD queries or repository methods, you call semantic method names and the library turns them into SQL.

For example:

db.get_user_by_id(123)

SELECT * FROM users WHERE id = ?

db.get_user_columns_name_and_email_by_status(status="active")

SELECT name,email FROM users WHERE status = ?

db.add_user(user={"name": "Alice", "email": "alice@example.com", "status": "active"})

INSERT INTO users (name,email,status) VALUES (?, ?, ?)

It supports:

sync and async database connections
keyword arguments
dataclasses
Pydantic models
dict-based reads/writes
simple dynamic SELECT / INSERT / UPDATE / DELETE
stored procedure/function calls with call_...
I’m intentionally not trying to build a full ORM like SQLAlchemy, Django ORM, or PonyORM. The goal is more like a tiny convention-based micro-ORM for simple CRUD, prototypes, scripts, admin tools, and small apps.

The current API is based on naming conventions like:

db.get_user_by_id(1)
db.get_users_by_status("active")
db.set_user_columns_status_by_id("inactive", 1)
db.delete_user(id=1)
I’m thinking about adding joins in a future major version, probably with names like:

db.get_user_with_posts_by_id(1)
I’d love feedback on the idea, naming conventions, and where the line should be between “useful tiny abstraction” and “oops, I accidentally rebuilt an ORM.”

GitHub: https://github.com/kamyar1979/guess_what

Top comments (0)