All Projects → kaukas → crystal-cassandra

kaukas / crystal-cassandra

Licence: MIT license
A Cassandra driver for Crystal

Programming Languages

crystal
512 projects
Makefile
30231 projects

Projects that are alternatives of or similar to crystal-cassandra

cassandra-CQL-exporter
A highly configurable utility to export whole Apache Cassandra keyspace or table structure/data to CQL scripts.
Stars: ✭ 19 (-5%)
Mutual labels:  cassandra, cql
gun-cassandra
Cassandra / Elassandra persistence layer for Gun DB 🔫
Stars: ✭ 14 (-30%)
Mutual labels:  cassandra, cql
marina
High-Performance Erlang Cassandra CQL Client
Stars: ✭ 50 (+150%)
Mutual labels:  cassandra, cql
haskell-tree-sitter
Haskell bindings for tree-sitter
Stars: ✭ 123 (+515%)
Mutual labels:  binding
janusgraph-docker
Yet another JanusGraph, Cassandra/Scylla and Elasticsearch in Docker Compose setup
Stars: ✭ 54 (+170%)
Mutual labels:  cassandra
cassandra-exporter
Simple Tool to Export / Import Cassandra Tables into JSON
Stars: ✭ 44 (+120%)
Mutual labels:  cassandra
background-service-lib
Essential classes for reliable background services.
Stars: ✭ 24 (+20%)
Mutual labels:  binding
pipeline
PipelineAI Kubeflow Distribution
Stars: ✭ 4,154 (+20670%)
Mutual labels:  cassandra
casper
Yelp's internal caching proxy, powered by Nginx and OpenResty at its core
Stars: ✭ 81 (+305%)
Mutual labels:  cassandra
hedis-ig
HEDIS FHIR-based Quality Reporting
Stars: ✭ 24 (+20%)
Mutual labels:  cql
luacc
Lua Code Combine
Stars: ✭ 36 (+80%)
Mutual labels:  binding
cassandra-prometheus
prometheus exporter for cassandra
Stars: ✭ 25 (+25%)
Mutual labels:  cassandra
odin-imgui
Odin binding for Dear ImGui
Stars: ✭ 37 (+85%)
Mutual labels:  binding
Troilus
Troilus is a Java client library for Cassandra.
Stars: ✭ 17 (-15%)
Mutual labels:  cassandra
cassandra-web
cassandra web ui
Stars: ✭ 61 (+205%)
Mutual labels:  cassandra
jsvm
Embeddable JavaScript Virtual Machine interface for Android, powered by Duktape.
Stars: ✭ 18 (-10%)
Mutual labels:  binding
dragome-sdk
Dragome is a tool for creating client side web applications in pure Java (JVM) language.
Stars: ✭ 79 (+295%)
Mutual labels:  binding
cassandra-data-apis
Data APIs for Apache Cassandra
Stars: ✭ 18 (-10%)
Mutual labels:  cassandra
necktie
Necktie – a simple DOM binding tool
Stars: ✭ 43 (+115%)
Mutual labels:  binding
cassandra-phantom
Cassandra + Phantom Example
Stars: ✭ 64 (+220%)
Mutual labels:  cassandra

Crystal DB API for Cassandra

A Crystal wrapper around the DataStax C/C++ Driver. It conforms to the crystal-db API.

Status

This is a personal project to create something meaningful while learning Crystal. There are no guarantees about future development, maintenance, or support. That said, if you need to use Crystal to query Cassandra this library could be a good starting point. YMMV.

Installation

Please make sure you have installed the DataStax C/C++ Driver. You can use "development" packages if they are available or build from source.

Then add this to your application's shard.yml:

dependencies:
  cassandra:
    github: kaukas/crystal-cassandra

Documentation

The latest Crystal Cassandra API documentation can be found here.

Usage

From the basic example:

require "cassandra/dbapi"

DB.open("cassandra://127.0.0.1/test") do |db|
  db.exec(<<-CQL)
    create table posts (
      id timeuuid primary key,
      title text,
      body text,
      created_at timestamp
    )
  CQL
  db.exec("insert into posts (id, title, body, created_at) values (now(), ?, ?, ?)",
          "Hello World",
          "Hello, World. I have a story to tell.",
          Time.now)
  db.query("select title, body, created_at from posts") do |rs|
    rs.each do
      title = rs.read(String)
      body = rs.read(String)
      created_at = rs.read(Time)
      puts title
      puts "(#{created_at})"
      puts body
    end
  end
end

Please refer to crystal-db for further usage instructions.

Types

crystal-cassandra supports all the DB::Any primitive types plus Int8 and Int16 and some additional value types:

  • date maps to Cassandra::DBApi::Date
  • time maps to Cassandra::DBApi::Time
  • uuid maps to Cassandra::DBApi::Uuid
  • timeuuid maps to Cassandra::DBApi::TimeUuid

Some of the collection types are also supported:

  • list maps to Array
  • set maps to Set
  • map maps to Hash

Casting

Cassandra supports nested collection types (lists, sets, maps, etc.). Since Crystal deprecated recursive aliases they can be represented with recursive structs. crystal-cassandra has Cassandra::DBApi::Any which performs a similar function to JSON::Any. You can pass collection parameters to queries wrapped with Cassandra::DBApi::Any (taken from the collections example):

alias Any = Cassandra::DBApi::Any

# Assuming `authors` is `list<text>`
db.exec("insert into posts (id, authors) values (now(), ?)",
        Any.new([Any.new("John Doe"), Any.new("Ben Roe")]))

db.query("select authors from posts") do |rs|
  rs.each do
    authors = rs.read(Array(Any))
    puts "Authors: #{authors.map { |author| author.as_s }.join(", ")}"
  end
end

You could do the same for the primitive values as well:

db.exec("insert into posts (id, title) values (now(), ?)",
        Any.new("Hello World"))

db.query("select title from posts") do |rs|
  rs.each do
    title = rs.read(Any)
    puts title.as_s
  end
end

but shortcuts are defined for them so Any can be skipped (see the basic example).

Development

Install the C/C++ Driver. The Makefile commands work on MacOS:

make build-cppdriver

Start a Docker container with an instance of Cassandra:

make start-cassandra

Run the tests:

crystal spec

Stop Cassandra when finished:

make stop-cassandra

Contributing

  1. Fork it (https://github.com/kaukas/crystal-cassandra/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

  • kaukas Linas Juškevičius - creator, maintainer
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].