whatyouhide/xandra


Fast, simple, and robust Cassandra/ScyllaDB driver for Elixir.

License: ISC

Language: Elixir

Keywords: cassandra, elixir, scylla


Xandra

hex.pm badge Documentation badge CI Hex.pm

Fast and robust Cassandra driver for Elixir.

Cover image

Xandra is a 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 for detailed explanation of how the supported features work.

Installation

Add the :xandra dependency to your mix.exs file:

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.

Connections or pool of connections can be started with Xandra.start_link/1:

{: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:

statement = "INSERT INTO users (name, postcode) VALUES ('Priam', 67100)"
{:ok, %Xandra.Void{}} = Xandra.execute(conn, statement, _params = [])

Preparing and executing a query:

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:

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 (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 file.

Project Statistics

Sourcerank 11
Repository Size 1.06 MB
Stars 388
Forks 53
Watchers 16
Open issues 4
Dependencies 3
Contributors 20
Tags 43
Created
Last updated
Last pushed

Top Contributors See all

Andrea Leopardi Aleksei Magusev Jens Fischer Harun Zengin Riccardo Binetti Cẩm Huỳnh jacquelineIO Kian-Meng Ang Kenneth Ito Yuri Artemev Alexander Alepis Karl Matthias Steve Cohen Andrew Phillipo Alisina Bahadori Kalaww Blake Tan Mattias Tegmyr Greg Rychlewski Žiga Magajna

Packages Referencing this Repo

xandra
Fast, simple, and robust Cassandra driver for Elixir.
Latest release 0.19.1 - Updated - 388 stars

Recent Tags See all

v0.19.1 July 10, 2024
v0.19.0 May 05, 2024
v0.18.1 October 30, 2023
v0.18.0 October 24, 2023
v0.18.0-rc.9 October 20, 2023
v0.18.0-rc.8 October 16, 2023
v0.18.0-rc.7 October 16, 2023
v0.18.0-rc.6 October 10, 2023
v0.18.0-rc.5 October 10, 2023
v0.18.0-rc.4 October 09, 2023
v0.18.0-rc.3 October 09, 2023
v0.18.0-rc.2 October 05, 2023
v0.18.0-rc.1 October 05, 2023
v0.17.0 July 27, 2023
v0.16.0 June 14, 2023

Something wrong with this page? Make a suggestion

Last synced: 2024-07-10 08:57:57 UTC

Login to resync this repository