3 ms·
I work on a Python project where I need to take class definitions and generate database query statements because all ORMs that currently exist don’t work for my
by alexchantavy 3y ago
I work on a Python project where I need to take class definitions and generate database query statements because all ORMs that currently exist don’t work for my needs. I'm currently doing this with string templates that I've defined by hand. Is there a smarter way?
I've looked into some compiler-like tools (can't remember the specific ones, sorry), and from what I can tell their code generation phase looks very similar to mine in that they use string templates.
- 89vision 3y agohttps://github.com/zio/zio-quill https://github.com/zio/zio-quill This library does exactly what you prescribe. Pretty sure under the hood it's using macros with string templates
- alexchantavy 3y agoVery cool, thank you. Anything in Python?
- 89vision 3y agoI tried searching for something similar in python but didn't find much
- noelwelsh 3y agoScala macros and quasiquote templates do have some notable differences to pure strings. The two main ones are: - the value that's constructed has to be valid code - macro "hygiene" is maintained
- aidos 3y agoWhy don’t ORMs work for you? Have you looked at sqlalchemy?
- alexchantavy 3y agoMy project uses the Neo4j graph database and the ORMs available here aren't great: they don't handle batched writes so they are super slow, or they do weird hacks like requiring that you run a webserver to let them work, or they don't use managed transaction functions so that write operations aren't automatically retried for you.
- aidos 3y agoAh yes. Fair enough. I worked on a project that used neo4j once and it was early enough when I joined that I was able to convince them to switch to Postgres before it was too late. It was the missing tooling more than the db itself (though, for 99% of what we were doing we didn’t gain anything from the graph model).