Packages
xandra
0.16.0
0.19.4
0.19.3
0.19.2
0.19.1
0.19.0
0.18.1
0.18.0
0.18.0-rc.9
0.18.0-rc.8
0.18.0-rc.7
0.18.0-rc.6
0.18.0-rc.5
0.18.0-rc.4
0.18.0-rc.3
0.18.0-rc.2
0.18.0-rc.1
0.17.0
0.16.0
0.15.0
0.15.0-rc.1
0.14.0
0.13.1
0.13.0
0.12.0
0.11.0
0.10.1
0.10.0
0.9.2
0.9.1
0.9.0
0.8.0
0.7.2
0.7.1
0.7.0
0.6.1
0.6.0
0.5.1
0.5.0
0.4.3
0.4.2
0.4.1
0.4.0
0.3.2
0.3.1
0.3.0
0.2.0
0.1.0
Fast, simple, and robust Cassandra driver for Elixir.
Current section
Files
Jump to
Current section
Files
README.md
# Xandra
[](https://hex.pm/packages/xandra)
[][documentation]
[](https://github.com/lexhide/xandra/actions/workflows/main.yml)
[](https://hex.pm/packages/xandra)
> Fast and robust Cassandra driver for Elixir.

Xandra is a [Cassandra][cassandra] driver built natively in Elixir and focused
on speed, simplicity, and robustness. This driver works exclusively with the
Cassandra Query Language v3 (CQL3) and native protocol *v3*, *v4*, and *v5*.
## Features
* ๐ฑ Connection pooling with automatic reconnections
* ๐ฏ Prepared queries (with local cache of prepared queries on a
per-connection basis) and batch queries
* ๐ Page streaming
* ๐๏ธ LZ4 compression
* ๐ฉโ๐ฉโ๐งโ๐ง Clustering with support for autodiscovery of nodes in the cluster
* ๐ Customizable retry strategies for failed queries
* ๐ฉโ๐ป User-defined types
* ๐ Authentication
* ๐ SSL encryption
See [the documentation][documentation] for detailed explanation of how the
supported features work.
## Installation
Add the `:xandra` dependency to your `mix.exs` file:
```elixir
defp deps do
[
{:xandra, "~> 0.14"}
]
end
```
Then, run `mix deps.get` in your shell to fetch the new dependency.
## Overview
The documentation is available [on HexDocs][documentation].
Connections or pool of connections can be started with `Xandra.start_link/1`:
```elixir
{:ok, conn} = Xandra.start_link(nodes: ["127.0.0.1:9042"])
```
This connection can be used to perform all operations against the Cassandra
server. Executing simple queries looks like this:
```elixir
statement = "INSERT INTO users (name, postcode) VALUES ('Priam', 67100)"
{:ok, %Xandra.Void{}} = Xandra.execute(conn, statement, _params = [])
```
Preparing and executing a query:
```elixir
with {:ok, prepared} <- Xandra.prepare(conn, "SELECT * FROM users WHERE name = ?"),
{:ok, %Xandra.Page{}} <- Xandra.execute(conn, prepared, [_name = "Priam"]),
do: Enum.to_list(page)
```
Xandra supports streaming pages:
```elixir
prepared = Xandra.prepare!(conn, "SELECT * FROM subscriptions WHERE topic = :topic")
page_stream = Xandra.stream_pages!(conn, prepared, _params = [], page_size: 1_000)
# This is going to execute the prepared query every time a new page is needed:
page_stream
|> Enum.take(10)
|> Enum.each(fn page -> IO.puts("Got a bunch of rows: #{inspect(Enum.to_list(page))}") end)
```
## Scylla support
Xandra supports [Scylla][scylladb] (version `2.x` to `5.x`) without the need to do anything in particular.
## License
Xandra is released under the ISC license, see the [LICENSE](LICENSE) file.
[documentation]: https://hexdocs.pm/xandra
[cassandra]: http://cassandra.apache.org
[scylladb]: https://www.scylladb.com/