Friday, January 16, 2015

Functional, fluent JDBC - FluentJdbc

Some projects relying on a relational database do just fine using a high-level ORM, some have need for more low-level control over the queries. Using JDBC directly for application development can be really cumbersome.It's so low-level it's better suited for tool- than application development .
There are many abstraction layer libraries over JDBC that add much needed syntax sugar and resource handling safety. Even so, sometimes I find it difficult to find a suitable one for the applications I work on. Either because they constrain in some way or have other unwanted properties (like transitive dependencies).

In some cases I implemented abstractions of my own and a library has started to emerge. I decided to collect those ideas and make it a library for easier reuse. A library that makes the most common SQL querying operations as simple, declarative as possible, is light-weight, has no dependencies. Most similar libraries don't make use of a fluent API which makes way for some interesting possibilities in terms of both readability and flexibility. Also I wanted to support operations that work with large amount of data (streaming, batching).

Some of FluentJdbc 's features: 
  • execution of select/insert/update/delete/alter/... statements as one-liners
  • parameter mapping (named, positional, supporting java.time, Optional, plugins for any types)
  • access to generated keys
  • result -> pojo mapping
  • transaction handling
  • big data (streaming select / batch insert)
Check out FluentJdbc's github page for usage details. The artifact is up in maven central, if you want to give it a shot:
Note: java 8 only

No comments:

Post a Comment