qcam / xandra

Fast, simple, and robust Cassandra driver for Elixir.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Xandra

Build Status Hex.pm

Fast, simple, and robust Cassandra driver for Elixir.

Cover image

Xandra is a Cassandra driver built natively in Elixir and focused on speed, simplicity, and robustness.

Features

This library is in its early stages when it comes to features, but we're already successfully using it in production at Football Addicts. Currently, the supported features are:

  • performing queries (including parameterized queries) on the Cassandra database
  • connection pooling
  • reconnections in case of connection loss
  • prepared queries (including a local cache of prepared queries on a per-connection basis)
  • batch queries
  • page streaming
  • compression
  • clustering (only random load balancing for now)
  • customizable retry strategies for failed queries
  • user-defined types

In the future, we plan to add more features, like more strategies for clustering and authentication support. See the documentation for detailed explanation of how the supported features work.

Installation

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

def deps() do
  [{:xandra, ">= 0.0.0"}]
end

and add :xandra to your list of applications:

def application() do
  [applications: [:logger, :xandra]]
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(host: "127.0.0.1", port: 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)

Contributing

Clone the repository and run $ mix test to make sure your setup is correct; you're going to need Cassandra running locally on its default port (9042) for tests to pass.

License

Xandra is released under the ISC license, see the LICENSE file.

About

Fast, simple, and robust Cassandra driver for Elixir.

License:ISC License


Languages

Language:Elixir 100.0%