Xandra v0.10.0 Xandra.Batch View Source

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.

Link to this section Summary

Functions

Adds a query to the given batch

Creates a new batch query

Link to this section Types

Link to this type type() View Source
type() :: :logged | :unlogged | :counter

Link to this section Functions

Link to this function add(batch, query, values \\ []) View Source
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)
Link to this function new(type \\ :logged) View Source
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()