I must say, I’m intrigued! What is your take on Jodd’s SQL building?
Boy bb = new Boy(); Girl bg = new Girl(); DbSqlBuilder dsb = sql() ._("select") // "select" .columnsAll("bb") // "bb.ID, bb.GIRL_ID, bb.NAME" .columnsIds("bg") // "bb.NAME, bg.ID" ._(" from") // " from" (hardcoded string) .table(bb, "bb") // "BOY bb" .table(bg, "bg") // ", GIRL bg" ._() // " " (single space) .match("bb", bb) // "(1=1)" since all bb fields are null ._(" and ") // " and " .match("bg", bg); // "(1=1)" since all bg fields are null.
5 thoughts on “The Jodd SQL Generator”
It does have a fancy banner web page. But probably it illustrates the point that while sometimes less is more, too little is indeed not enough.
Much better example would be usage of SQL templates (https://jodd.org/doc/db/template-sql.html), not a builder. While builder serves it purpose, it is much, much more developer friendly to use SQL templates. SQL Templates are just convenient string where you can eg refer entities and not real tables etc. It is worth to mention that this is part of DbOom – a mapping tool, so it is not just a simple sql generator. And it happened to be quite enough in real world (when you target one, specific db): you have mapping, and build relations in runtime, and have that all mapped. Similar to iBatis.
Hi there, and thanks for the authoritative feedback! Right, I missed the templating functionality in Jodd. I’ll fix that with a follow-up blog post by the end of the year. Is there anything else you’d like me to mention?
Depends how long you want to write about it :) Maybe its worth it to mention that the idea behind the template sql (TSql) is to ‘extend’ the sql and introduce entities and shorten some common code. So you still write sql for target database, just easier :)
Thanx for working on this, let me know if you need more :)
Yes, such SQL templating engines are quite popular. I’ve recently blogged about another one called ElSql… I’m really hoping to be able to implement templating in jOOQ, soon, though.