I’ve had success in Java with Freemarker. It’s a templating engine so you’re just producing strings. But you can add typing; use variables, loops, and conditionals; and include other templates for sub query reuse.
IntelliJ has a plug-in.
It’s a nice compromise between crafting strings vs SQL DSL.
As for the objects, you can get very far with everything being a Map until you really need to add a class or two. :)
Absolutely. One of the things I like about Groovy is that it solves the other half of that equation because it has the built in map constructor and built in SQL APIs that work with it. So you can actually do
class Foo {
Long id
String name
...
}
Foo foo = new Foo(db.firstRow("select * from foo limit 1"))
And it all just works if the database columns match the fields of Foo. And if you just do
Foo foo = new Foo(db.firstRow("select name from foo limit 1"))
Then you get a `foo` with only the name populated, etc, and you got type safety, easy direct, efficient SQL queries and the ability to test your code without hitting the database, all without imposing any "leaky" abstractions that cause all the problems.
IntelliJ has a plug-in.
It’s a nice compromise between crafting strings vs SQL DSL.
As for the objects, you can get very far with everything being a Map until you really need to add a class or two. :)