com.softinio.duck4s

Members list

Packages

The algebra package contains the fundamental types, error hierarchies, and algebraic data structures that form the foundation of the duck4s library. These types provide type-safe, functional abstractions over DuckDB's JDBC interface.

Algebra Package: Core Types and Data Structures

The algebra package contains the fundamental types, error hierarchies, and algebraic data structures that form the foundation of the duck4s library. These types provide type-safe, functional abstractions over DuckDB's JDBC interface.

Core Types

Error Handling

Configuration

Query Execution

Batch Operations

Type Classes for Batch Operations

The algebra package provides powerful type classes for type-safe batch operations:

// Built-in support for tuples up to 4 elements
batch.addBatch((1, "Alice"))                    // (Int, String)
batch.addBatch((1, "Alice", 25))                // (Int, String, Int)
batch.addBatch((1, "Alice", 25, true))          // (Int, String, Int, Boolean)
batch.addBatch((1, "Alice", 25, 999.99))        // (Int, String, Int, Double)

// Built-in support for primitive types
stmt.setInt(1, 42)
stmt.setString(2, "hello")
stmt.setDouble(3, 3.14)
stmt.setBoolean(4, true)
stmt.setLong(5, 1000L)

// Option support for nullable values
stmt.setString(1, Some("value"))    // Sets the string value
stmt.setString(1, None)             // Sets NULL

Custom Type Class Instances

You can provide custom ParameterBinder instances for your own types:

case class UserId(value: Long)

given ParameterBinder[UserId] with
 def bind(stmt: DuckDBPreparedStatement, index: Int, value: UserId): Either[DuckDBError, Unit] =
   stmt.setLong(index, value.value).map(_ => ())

// Now UserId can be used in batch operations
batch.addBatch((UserId(123), "Alice"))

Error Handling Patterns

All operations return Either[DuckDBError, T] for functional composition:

for
 stmt <- conn.prepareStatement("INSERT INTO users VALUES (?, ?)")
 _ <- stmt.setInt(1, 1)
 _ <- stmt.setString(2, "Alice")
 result <- stmt.executeUpdate()
yield result

Resource Management

Types in this package follow consistent resource management patterns:

  • All resource types implement AutoCloseable
  • Prefer with* methods for automatic cleanup
  • Resources are cleaned up even on errors
  • Nested resource usage is safely composed

Attributes

See also

com.softinio.duck4s.DuckDBConnection for the main connection interface

Since

0.1.0

Type members

Classlikes

A Scala 3 wrapper for DuckDB JDBC connections providing type-safe, functional access to DuckDB.

A Scala 3 wrapper for DuckDB JDBC connections providing type-safe, functional access to DuckDB.

This class wraps the underlying JDBC connection and provides idiomatic Scala methods for executing queries, managing transactions, and working with prepared statements.

Value parameters

underlying

The underlying JDBC connection to DuckDB

Attributes

Constructor

Creates a new DuckDB connection wrapper

See also

com.softinio.duck4s.algebra.DuckDBConfig for connection configuration options

Since

0.1.0

Example
 import com.softinio.duck4s.* import com.softinio.duck4s.algebra.*
// Create an in-memory connection val result =
DuckDBConnection.withConnection() { conn => for _ <-
conn.executeUpdate("CREATE TABLE users (id INTEGER, name VARCHAR)") _ <-
conn.executeUpdate("INSERT INTO users VALUES (1, 'Alice')") rs <-
conn.executeQuery("SELECT * FROM users") yield while rs.next() do
println(s"${rs.getInt("id")}: ${rs.getString("name")}") rs.close() } 
Companion
object
Supertypes
class Object
trait Matchable
class Any

Attributes

Companion
class
Supertypes
class Object
trait Matchable
class Any
Self type

Extensions

Extensions

extension (connection: DuckDBConnection)

Executes a SQL query and returns the result set.

Executes a SQL query and returns the result set.

This method executes a SELECT query and returns a result set that can be used to iterate over the returned rows. The result set should be closed when no longer needed.

Value parameters

sql

The SQL SELECT query to execute

Attributes

Returns

Either a algebra.DuckDBError.QueryError if execution fails, or a algebra.DuckDBResultSet

See also

algebra.DuckDBResultSet for result set navigation and data extraction

Since

0.1.0

Example
\n * for rs <- conn.executeQuery("SELECT * FROM users WHERE age >
 18") yield while rs.next() do println(s"User: ${rs.getString("name")}")
 rs.close() 

\n *

Executes a SQL update statement (INSERT, UPDATE, DELETE, DDL).

Executes a SQL update statement (INSERT, UPDATE, DELETE, DDL).

This method executes SQL statements that modify the database or its structure. It returns the number of affected rows for DML statements.

Value parameters

sql

The SQL statement to execute (INSERT, UPDATE, DELETE, CREATE TABLE, etc.)

Attributes

Returns

Either a algebra.DuckDBError.QueryError if execution fails, or the number of affected rows

Since

0.1.0

Example
\n * for count <- conn.executeUpdate("INSERT INTO users (name, age)
 VALUES ('Alice', 25)") yield println(s"$count rows inserted") 

\n *

def withBatch[T](sql: String)(block: DuckDBBatch => Either[DuckDBError, T]): Either[DuckDBError, T]

Executes a block of operations with a batch that is automatically closed.

Executes a block of operations with a batch that is automatically closed.

This method creates a batch for the given SQL statement, executes the provided block, and ensures the batch is properly closed regardless of the outcome.

Type parameters

T

The type of the successful result

Value parameters

block

A function that receives the batch and returns an Either with the result

sql

The SQL statement to prepare for batch execution

Attributes

Returns

Either a algebra.DuckDBError.QueryError if preparation or execution fails, or the result of the block

See also

DuckDBConnection.prepareBatch for manual batch management

algebra.DuckDBBatch for batch parameter binding and execution

Since

0.1.0

Example
\n * conn.withBatch("INSERT INTO users (id, name) VALUES (?, ?)") {
 batch => for _ <- batch.addBatch(1, "Alice") _ <- batch.addBatch(2,
 "Bob") result <- batch.executeBatch() yield result } 

\n *

Executes a block of operations with a prepared statement that is automatically closed.

Executes a block of operations with a prepared statement that is automatically closed.

This method creates a prepared statement, executes the provided block, and ensures the statement is properly closed regardless of the outcome.

Type parameters

T

The type of the successful result

Value parameters

block

A function that receives the prepared statement and returns an Either with the result

sql

The SQL statement to prepare

Attributes

Returns

Either a algebra.DuckDBError.QueryError if preparation or execution fails, or the result of the block

See also

DuckDBConnection.prepareStatement for manual prepared statement management

algebra.DuckDBPreparedStatement for parameter binding and execution

Since

0.1.0

Example
\n * conn.withPreparedStatement("SELECT * FROM users WHERE id = ?") {
 stmt => for _ <- stmt.setInt(1, 42) rs <- stmt.executeQuery() yield rs }

\n *