Giter Club home page Giter Club logo

elixir-cassandra's Introduction

Cassandra

Build Status Hex.pm Hex.pm Coverage Status

An Elixir driver for Apache Cassandra.

This driver works with Cassandra Query Language version 3 (CQL3) and Cassandra's native protocol v4.

Features

  • Automatic peer discovery
  • Automatic connection managment (reconnect on connection loss and discover new nodes)
  • Configurable load-balancing/reconnection policies
  • Asynchronous execution through Tasks
  • Prepared statements with named and position based values
  • Token based load-balancing policy
  • Automatic prepare and cache prepared statements per host
  • Result paging

Installation

Add cassandra to your list of dependencies in mix.exs:

def deps do
  [{:cassandra, "~> 1.0.0-beta.5"}]
end

Quick Start

defmodule Repo do
  use Cassandra
end

{:ok, _} = Repo.start_link
# uses "127.0.0.1:9042" as contact point by default
# discovers other nodes on first connection

Repo.execute """
  CREATE KEYSPACE IF NOT EXISTS test
    WITH replication = {'class':'SimpleStrategy','replication_factor':1};
  """, consistency: :all

Repo.execute """
  CREATE TABLE IF NOT EXISTS test.users (
    id timeuuid,
    name varchar,
    age int,
    PRIMARY KEY (id)
  );
  """, consistency: :all

insert = "INSERT INTO test.users (id, name, age) VALUES (?, ?, ?);"

users = [
  %{name: "Bilbo", age: 50},
  %{name: "Frodo", age: 33},
  %{name: "Gandolf", age: 2019},
]

users
|> Task.async_stream(&Repo.execute(insert, values: [Cassandra.UUID.v1, &1.name, &1.age]))
|> Enum.to_list

Repo.execute("SELECT * FROM test.users;")

# %CQL.Result.Rows{
#   columns: ["id", "age", "name"],
#   rows_count: 3,
#   rows: [
#     ["831e5df2-a0e1-11e6-b9af-6d2c86545d91", 2019, "Gandolf"],
#     ["831e5df1-a0e1-11e6-b9af-6d2c86545d91", 33, "Frodo"],
#     ["831e5df0-a0e1-11e6-b9af-6d2c86545d91", 50, "Bilbo"]
#   ]
# }

Todo

  • Compression
  • Batch statement
  • Authentication and SSL encryption
  • User Defined Types

elixir-cassandra's People

Contributors

hzamani avatar alirajabi avatar clouds56 avatar parroty avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.