View Source Xandra.Batch (Xandra v0.19.1)
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.
Note that the t/1
type is not documented as it's not meant
for public use. If you want to use batches in your typespecs, use t/0
.
Summary
Types
@type t() :: t(type())
@type type() :: :logged | :unlogged | :counter
Functions
@spec add(t(), Xandra.statement() | Xandra.Prepared.t(), Xandra.values()) :: 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)
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()