Liking cljdoc? Tell your friends :D

Scarab

A Clojure wrapper of Scalar DB

Usage

  • You need to create a keyspace and a table for Scalar DB before use

Storage (non transactional operation)

(require '[scarab.core :as c])
(require '[scarab.storage :as st])

(let [properties (c/create-properties {:nodes "192.168.1.32,192.168.1.23"
                                       :username "cassandra"
                                       :password "cassandra"})
      storage (st/setup-storage properties)
      keys    [{:id {:value 1 :type :int}}]
      values  {:val {:value 111 :type :int}}]

      (st/put! storage "keyspace" "table" keys values)

      (st/get! storage "keyspace" "table" keys))
  • Columns are represented as a map

      {:column-name1 {:value val1 :type :value-type1}
       :column-name2 {:value val2 :type :value-type2}}
    
    • :value-type supports :bigint, :blob, :boolean, :double, :float, int, and text
  • keys which has partition keys and clustering keys are represented as a vector of maps as below

      [{:pk1 {:value "partition key 1" :type :text}
        :pk2 {:value "partition key 2" :type :text}}
       {:ck1 {:value "clustering key 1" :type :text}
        :ck2 {:value "22" :type :int}}])
    
    • The first example has only a partition key

Transaction

(require '[scarab.core :as c])
(require '[scarab.transaction :as t])

(let [properties (c/create-properties {:nodes "192.168.1.32,192.168.1.23,192.168.1.11"
                                       :username "cassandra"
                                       :password "cassandra"})
      keyspace "testks"
      table    "tx"
      tx       (t/setup-transaction properties)
      keys     [{:id {:value 1 :type :int}}]
      values   {:val {:value 111 :type :int}}]

      (t/start! tx)
      (t/put! tx keyspace table keys values)
      (t/commit! tx)

      ; You have to start a new transaction after commit
      (t/start! tx)
      (let [cur-val (:value (:val (t/get! tx keyspace table keys)))
            new-val {:val {:value (+ cur-val 222) :type :int}}]
        ; update
        (t/put! tx keyspace table keys new-val))
      (t/commit! tx))

License

Copyright © 2018 Yuji Ito

Distributed under the Eclipse Public License version 1.0 or Apache Public License 2.0.

Can you improve this documentation?Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close