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

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.



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


Scala 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


Very cool, thank you. Anything in Python?


I tried searching for something similar in python but didn't find much


Why don’t ORMs work for you? Have you looked at sqlalchemy?


My 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.


Ah 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).




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

Search: