Show HN: JinjaSQL – Generate SQL Queries using a Jinja Template
github.com
github.com
When we switched to Clojure (from nodejs), we decided against any kind of ORM and use HugSQL which allows us to write "plain SQL" in .sql files while still using parameters.
Couldn't immediately think of other cases, but that one example sounds useful for this.
Skipping in clauses altogether - for now, you can handle that using an if condition.
It allows you to simply write SQL in a GString using placeholders that get replaced with parameters before being sent to the database, here's an example from the Javadoc:
sql.execute "insert into PROJECT (id, name, url) values ($map.id, $map.name, $map.url)"
Works great with Groovy's multiline strings.
[1] https://github.com/hashedin/jinjasql#when-to-use-jinjasql
The few times when I do need to force a certain SQL syntax that the ORM won't give me, I drop down to SQL. But doing that doesn't magically make all queries faster.
It depends. Anyone working on that code now needs to learn the ORM, the SQL and how to let the ORM generate that SQL for anything beyond the basics.
Any variables are automatically replaced by placeholder strings. You also get an array of bind parameters. You then use your database library to bind the parameters into the placeholders.