3 ms·
I think JOOQ "Fluent API" is a kind of silly. Just embed the SQL statement in a string. In same way you would embed a snippet of HTML, XML or anything else.
by throwaway4good 6y ago
I think JOOQ "Fluent API" is a kind of silly.
Just embed the SQL statement in a string.
In same way you would embed a snippet of HTML, XML or anything else.
(You can remove some of the boiler plate of a classic Java prepared statement using a library though ... nothing wrong in that.)
- throwaway4good 6y agoOne of the advantages of just having your embedded SQL as a string is that you can copy it back and forth between a SQL console when you are developing. Instead of something like this: Query query = create.select(field("BOOK.TITLE"), field("AUTHOR.FIRST_NAME"), field("AUTHOR.LAST_NAME")) .from(table("BOOK")) .join(table("AUTHOR")) .on(field("BOOK.AUTHOR_ID").eq(field("AUTHOR.ID"))) .where(field("BOOK.PUBLISHED_IN").eq(1948)); Plus you may sit with a SQL dialect not supported by the "Fluent API".
- chrizel 6y ago> Just embed the SQL statement in a string. This makes sense for simple software, but jOOQ generates DB specific SQL queries depending on your DB dialect. E.g. we have a big product which supports nearly all big databases and jOOQ abstracts away the DB specific stuff wonderfully.
- throwaway4good 6y agoKeeping it simple in general also makes sense for complex software ...
- shock 6y agoJOOQ's fluent API gives you safety since it is introspected from the actual DB structure. Invalid code does not compile, instead of blowing up in production at runtime as it would in the case of the SQL string.
- kitd 6y agoIf you don't like JOOQ and prefer to use bona fide SQL statements, JDBI [1] is a battle-tested OSS alternative that maps Java objects to statements. [1] https://github.com/jdbi/jdbi https://github.com/jdbi/jdbi
- mateuszf 6y agoJDBI is awesome :)