Just use JOOQ or any other kind of library that removes the boilerplate and is 100x more maintainable and productive.
Just use JOOQ or any other kind of library that removes the boilerplate and is 100x more maintainable and productive.
Just use an ORM or any other kind of library that removes the boilerplate and is 100x more maintainable and productive.
See how useful it is to not explain anything.
Far easier to write correct sql than to convince the orm how to form correct sql.
For smaller systems it might be ok I guess, but stay alive long enough and you 'll see that sooner or later every small system desires to grow, grow and grow!
good ORMs all have a way to fine-control the underlying statements to avoid querying individual rows one by one.
I'm fairly proficient with sql queries and i still don't like writing sql queries and binding to objects manually
No, that makes no sense.
If you have to investigate 2 places where performance issues have cropped up and hand-write the SQL in those places, while 95% of your application works just fine, how did you lose all the benefits?
My SQL competency was fine from the beginning, thank you very much.
However, your comparison does not make sense. JOOQ and similar libraries don't make you write SQL, even if their API is closer to SQL than what most ORMs do.
If you replace "ORM" in your example with NoSQL or some other technology that directly competes with SQL then it would make sense.
Just my experience so far.
2. ORMs work just fine in lots of applications. There’s no real need to replace them.
3. JOOQ does not remove enough boilerplate and it’s not 100x more maintainable.
If your app does not have a requirement to be DBMS agnostic then DAO (Data Access Objects) frameworks like Spring JDBC or MyBATIS might meet your needs. If you don’t like using an Internal DSL and/or embedding SQL in your code, then a YeSQL framework like HugSQL might work for you.
For a strictly typed object orient language like Java, no single data access framework style has emerged as ideal. All have to address the same issues: integrating DDL/DML into source control, supporting different DBMSes, generating DAOs, and DDL migrations.
I don’t really have a horse in this race (in Clojure there’s no need to map between results and idiomatic data structures in your domain, and you can add as much or as little schema/type checking as you want) but in previous lives doing OOP I have never lamented them 5% of problematic SQL queries to the point I’d throw away the rest that an ORM gives me. Just break out into a more powerful query language, hide it behind an interface and you still get to return meaningful objects in your domain.
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.)
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".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.
You can use something like https://sqitch.org/ or https://flywaydb.org/ or https://www.liquibase.org/ or https://github.com/rust-db/refinery where ideally your migrations should be written in plain sql (or a language that can output plain sql so you can see what it does). Then it's a matter of running those sql queries and knowing which migrations already happened.
> So ideally, the app reflects the DB schema in some type-safe manner.
That's right! But there is no need to use an ORM for that. JooQ and other libraries (in my world it would be Quill https://getquill.io/) do that for you.
Two examples in .NET world: Roundhouse [0] and FluentMigrator [1].
[0] - https://github.com/chucknorris/roundhouse [1] - https://github.com/fluentmigrator/fluentmigrator