DuckDBIO

com.softinio.duck4s.effect.DuckDBIO
object DuckDBIO

Cats-effect integration for duck4s, providing cats.effect.Resource-based connection management and fs2.Stream-based result set streaming.

All JDBC calls are wrapped in cats.effect.IO.blocking to avoid blocking the cats-effect thread pool. Errors are raised as DuckDBException rather than returned as Either values.

Attributes

Note

DuckDB connections are NOT thread-safe. Do not share a single connection across fibers. Use duplicate() or open separate connections per fiber.

Example
 import com.softinio.duck4s.effect.*
val program: IO[Unit] = DuckDBIO.connect().use { conn => for _ <-
conn.executeUpdateIO("CREATE TABLE t (id INTEGER)") _ <-
conn.executeUpdateIO("INSERT INTO t VALUES (1)") rows <-
DuckDBIO.stream(conn, "SELECT id FROM t")(_.getInt("id")).compile.toList _
<- IO(println(rows)) yield () } 
Graph
Supertypes
class Object
trait Matchable
class Any
Self type
DuckDBIO.type

Members list

Value members

Concrete methods

def connect(config: DuckDBConfig = ...): Resource[IO, DuckDBConnection]

Acquires a DuckDB connection as a cats-effect cats.effect.Resource. The connection is closed automatically on release.

Acquires a DuckDB connection as a cats-effect cats.effect.Resource. The connection is closed automatically on release.

Value parameters

config

Database configuration. Defaults to in-memory mode.

Attributes

Returns

A cats.effect.Resource that manages the connection lifecycle.

def stream[A](conn: DuckDBConnection, sql: String)(f: DuckDBResultSet => A): Stream[IO, A]

Streams rows from a SQL SELECT query as a fs2.Stream.

Streams rows from a SQL SELECT query as a fs2.Stream.

The result set is opened and closed within the stream's resource scope. Each row is mapped using the provided function while the cursor is positioned at that row.

Type parameters

A

The type of each emitted element.

Value parameters

conn

The DuckDB connection to use for the query.

f

Row mapper called for each row with the result set positioned at that row.

sql

The SQL SELECT statement to execute.

Attributes

Returns

A fs2.Stream that emits one element per row.