Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

From what little I've seen of it, SQLAlchemy on python might fit. It's not an ORM, it's a query builder.


It has separate, stackable layers for query building, data mapping, ORM, and ActiveRecord-ish declarative models. You can pick the parts you want and ignore the rest.

The query builder makes composable SQL syntax trees from raw text or Python objects. Executing those as queries gives you rows of tuples.

If you teach it the shapes of your data with the data mapper, you can query in terms of your tables (instead of ad-hoc column names) and get rows of populated custom objects.

On top of the mapper, the ORM defines your application-level data model, manages relationships and loading strategies, and powers up the query builder with the usual stuff like automatic joins (if you want them). You can still build composable queries, now against your application objects, but you can also work directly with the model like a standard ORM.

If you know you want the whole thing from the start, Declarative will let you do the mapping and the ORMing all at once by defining a class.


Even better we now have SQLModel¹, which bridges SQLAlchemy and Pydantic.

¹: https://sqlmodel.tiangolo.com/


Too bad it is not ideal compared to a full-blown SQLAlchemy setup, and it's not production quality yet. Hopefully he'll get it done sooner or later.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: