Just updated a library which makes life much easier when speaking about databases...
When streams were introduced in java I got myself thinking of how I can leverage it with databases. It is "pretty common" task to write SQL queries and process the results within Java. And the more I was ought to deal with prepared statements, result sets, all those SQLException
s etc., the more I was disappointed. Searching the WEB for solutions where I wanted to find two worlds collided conveniently - I found no suitable one! Of course there are many libraries that afford some, but neither of them suited me. I wanted something else. Therefore I decided to write one myself for myself.
My goals...
...were based on my background experience:
- No prepared boilerplate and
SQLException
s - Executing arbitrary scripts
- Minimal configuration
- "Real" streams (lazily data fetching)
- Raw SQL
- Database is just a method invocation
and some others - don't remember them all :)
So after some time I ended up with this:
A brief
1 - Get:
<dependency>
<groupId>com.github.buckelieg</groupId>
<artifactId>jdbc-fn</artifactId>
<version>1.0</version>
</dependency>
2 - Setup:
DB db = DB.builder()
.withMaxConnections(10)
.build(() -> DriverManager.getConnection("vendor-specific-string"));
3 - Use:
Collection<String> names = db.select("SELECT name FROM users WHERE ID IN (?, ?)", 1, 2).execute(rs -> rs.getString("name")).collect(Collectors.toList());
Happy to share: jdbc-fn project.
Top comments (0)