4 ms·
I always though it would be a nice alternative to an ORM: having a tool that take a marshmallow/pydantic/whatever model, optionally passing it additional db spe
by BiteCode_dev 6y ago
I always though it would be a nice alternative to an ORM: having a tool that take a marshmallow/pydantic/whatever model, optionally passing it additional db specific options, then it generates a bunch of sql files you can call with aiosql. The whole things would then let you optionally get the result wrapped in a model if you need to, with ORM like helpers for common CRUD things.
That would have the benefit of the standardized api of an ORM and the flexibility of SQL, without the coupling.
- polyrand 6y agoAbsolutely! I think it should be doable, FastAPI and other libraries do heavy Pydantic model inspection, and some do automatic code generation. I should explore this a bit more.
- BiteCode_dev 6y agoIt also has some nice properties: - because you have all your queries written in the same place, when you create a db migration, you know where to look for code to update, and can even perform some automatically. - sql queries could be turned into a stored procedure with a simple marking, without changing any code. Of course the downside is that dynamically exploring data is not as easy as with an ORM.