DuckDBBatch

com.softinio.duck4s.algebra.DuckDBBatch
case class DuckDBBatch(preparedStatement: DuckDBPreparedStatement) extends AutoCloseable

A batch operation wrapper for executing multiple parameter sets efficiently.

This class provides a type-safe way to execute batch operations with prepared statements. It uses type classes (BatchBinder and ParameterBinder) to automatically bind parameters of various types, making batch operations both safe and convenient.

Value parameters

preparedStatement

the prepared statement to use for batch operations

Attributes

See also

BatchBinder for parameter binding type class

ParameterBinder for individual parameter binding

DuckDBBatchResult for batch execution results

Since

0.1.0

Example
 // Batch insert with tuples val batch = for { stmt <-
 connection.prepareStatement("INSERT INTO users (name, age) VALUES (?, ?)")
 batch <- Right(DuckDBBatch(stmt)) _ <- batch.addBatch(("Alice", 25),
 ("Bob", 30), ("Charlie", 35)) result <- batch.executeBatch() } yield
 result
// Batch update with different parameter types val updateBatch = for { stmt
<- connection.prepareStatement("UPDATE products SET price = ?, active = ?
WHERE id = ?") batch <- Right(DuckDBBatch(stmt)) _ <- batch.addBatch((19.99,
true, 1), (29.99, false, 2)) result <- batch.executeBatch() } yield result
Graph
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Members list

Value members

Concrete methods

def addBatch[T](values: T*)(using binder: BatchBinder[T]): Either[DuckDBError, DuckDBBatch]

Adds multiple parameter sets to the batch for execution.

Adds multiple parameter sets to the batch for execution.

This method uses the BatchBinder type class to automatically bind parameters of the specified type. The type class provides compile-time safety for parameter binding.

Type parameters

T

the type of parameter values (typically tuples)

Value parameters

binder

the implicit BatchBinder for type T

values

the parameter values to add to the batch

Attributes

Returns

Right(this) on success, Left(DuckDBError) on failure

Since

0.1.0

Example
 // Adding tuples to batch batch.addBatch( ("Alice", 25), ("Bob",
 30), ("Charlie", 35) )
// Adding single values with Option support batch.addBatch( ("Product A",
Some(19.99)), ("Product B", None) ) 

Clears all parameter sets from the batch without executing them.

Clears all parameter sets from the batch without executing them.

This method removes all previously added parameter sets from the batch, allowing you to start over with new parameter sets.

Attributes

Returns

Right(this) on success, Left(DuckDBError) on failure

Since

0.1.0

Example
 val result = for { batch <- Right(DuckDBBatch(stmt)) _ <-
 batch.addBatch(("Alice", 25)) _ <- batch.clearBatch() // Remove Alice _
 <- batch.addBatch(("Bob", 30)) // Add Bob instead result <-
 batch.executeBatch() } yield result 
def close(): Unit

Closes the underlying prepared statement and releases database resources.

Closes the underlying prepared statement and releases database resources.

This method closes the prepared statement used by this batch. It should be called when the batch is no longer needed to free database resources.

Attributes

Since

0.1.0

Example
 val batch = DuckDBBatch(stmt) try { // Use the batch... } finally {
 batch.close() } 

Executes all batched parameter sets and returns the results.

Executes all batched parameter sets and returns the results.

This method executes all parameter sets that have been added to the batch and returns a DuckDBBatchResult containing update counts and statistics.

Attributes

Returns

Right(DuckDBBatchResult) on success, Left(DuckDBError) on failure

See also

DuckDBBatchResult for result details

Since

0.1.0

Example
 val result = for { batch <- Right(DuckDBBatch(stmt)) _ <-
 batch.addBatch(("Alice", 25), ("Bob", 30)) result <-
 batch.executeBatch() } yield result
result match { case Right(batchResult) => println(s"Successful operations:
${batchResult.successCount}") println(s"Failed operations:
${batchResult.failureCount}") case Left(error) => println(s"Batch
execution failed: $error") } 

Inherited methods

Attributes

Inherited from:
Product

Attributes

Inherited from:
Product