Xandra v0.4.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
Types
Functions
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)