druvu-lib-jdbc

A lightweight SQL-first JDBC wrapper. Work with SQL directly, skip the ORM complexity.

View on GitHub


Overview

druvu-lib-jdbc is a database access layer built on Spring JDBC that treats SQL statements as first-class citizens. It provides a fluent API for constructing and executing SQL without hiding the SQL behind an ORM.


Quick Examples

Basic query with positional parameters:

DbConfig config = DbConfig.of("myDb", "jdbc:postgresql://localhost/mydb",
    "user", "pass", "org.postgresql.Driver", "SELECT 1");
DbAccess db = DbAccessFactory.create(config);

List<Map<String, Object>> users = db.select(
    SimpleSql.fromString("SELECT * FROM users WHERE status = ?")
        .with("active"));

Named parameters:

db.select(SimpleSql.named("SELECT * FROM users WHERE id = :id AND status = :status")
    .with("id", userId)
    .with("status", "active"));

Custom row mapping:

List<User> users = db.select(
    SimpleSql.query("SELECT id, name FROM users WHERE status = ?",
        (rs, rowNum) -> new User(rs.getInt("id"), rs.getString("name")))
    .with("active"));

Transactions:

db.inTransaction(tx -> {
    tx.update(SimpleSql.fromString("UPDATE accounts SET balance = balance - ?")
        .with(amount));
    return tx.select(SimpleSql.fromString("SELECT * FROM accounts"));
});

Features

Feature Description
Fluent API Chain methods for building SQL statements
Positional & Named Params Support for ? and :param binding
SQL from Files Load SQL from classpath resources or files
Dynamic IN Clauses ??? expands to multiple ? for collections
Row Streaming Memory-efficient processing of large datasets
Transactions Simple transaction support with rollback
Debug Output stmt.toDebugString() renders SQL with bound values

Requirements

  • Java 17+
  • Spring JDBC (dependency)

License

Apache License 2.0



Back to top

Copyright © 2026 druvu.com. All rights reserved.

This site uses Just the Docs, a documentation theme for Jekyll.