Xandra v0.7.1 Xandra.Batch

Represents a batch of simple and/or prepared queries.

This module provides a data structure that can be used to group queries and execute them as a Cassandra BATCH query. Batch queries can be executed through Xandra.execute/3 and Xandra.execute!/3; see their respective documentation for more information.

Summary

Functions

Adds a query to the given batch

Creates a new batch query

Types

t(type)
type()
type() :: :logged | :unlogged | :counter

Functions

add(batch, query, values \\ [])
add(t, Xandra.statement | Xandra.Prepared.t, [term]) :: t

Adds a query to the given batch.

query has to be either a simple query (statement) or a prepared query. Note that parameters have to be added alongside their corresponding query when adding a query to a batch. In contrast with functions like Xandra.execute/4, simple queries in batch queries only support positional parameters and do not support named parameters; this is a current Cassandra limitation. If a map of named parameters is passed alongside a simple query, an ArgumentError exception is raised. Named parameters are supported with prepared queries.

Examples

prepared = Xandra.prepare!(conn, "INSERT INTO users (name, age) VALUES (?, ?)")

batch =
  Xandra.Batch.new()
  |> Xandra.Batch.add(prepared, ["Rick", 60])
  |> Xandra.Batch.add(prepared, ["Morty", 14])
  |> Xandra.Batch.add(prepared, ["Jerry", 35])
  |> Xandra.Batch.add("DELETE FROM users WHERE name = 'Jerry'")

Xandra.execute!(conn, batch)
new(type \\ :logged)
new(type) :: t

Creates a new batch query.

type represents the type of the batch query (:logged, :unlogged, or :counter). See the Cassandra documentation for the meaning of these types.

Examples

batch = Xandra.Batch.new()