Categories
Development

MyHome Crud

Lets start with create/update/delete using good old fashioned WebMvc Spring, Kotlin and JOOQ.

Following checkpoint has:

  • Gradle kts build script
  • JOOQ code generation from DB
  • SQL script to initialize DB
  • Controllers and repositories to create/update/delete many entities.
  • Some basic error handling
  • Some extension functions.
  • Open API auto-generated

https://github.com/MavoCz/myhome/tree/checkpoint-01-crud

Notes:

To set up logging of JOOQ queries:

Which gives you awesome insight into every SQL query and result:

Code generation of JOOQ works well, but its a bit hard to set up. The configuration below scans a database and creates JOOQ table definitions and records.

It can automatically map Kotlin/Java enums for you, but each needs to be configured. See lines 27.

Kotlin gotcha: For some reason injection into super class did not work without open keyword for every property.

Some notes to DB update code:

Don’t forget to call execute at the end. updatedRecord is R : Record, where record is org.jooq.Record. Idea keeps importing java.lang.Record which is quite annoying. updatedRecord creates a minimal set or changes, so if it contains only one changed field, it will have only one field in final SQL. Nice.

Jooq Records are a nice way to hold/manipulate/transfer DB data to insert/update/result.

It can be mapped nicely to and from a DTO/data class, generator is able to create on per entity record class with convenience methods named after columns. And if you don’t want to deal with those pesky DTOs, it can serialize data to JSON too.

Categories
Development

Copilot experiments

Since its that time of the year again and holiday spirit is once again elevated by advent of code challenge, I decided to participate, but this time with the help of Github AI assistant Copilot.

So start 2 month trial, install Idea plugin and here we go. And the first impressions were … not great. At first it did not generate anything. I spent 10 minutes with trying few things. Then I found out how to define method and first sudgestions appeared.

It seemed like it was reading my mind … code was sometimes usable as is, sometimes needed a bit of tweaking, rarely was completely off. But I was amazed about how it worked out