cassy-0.2.0.3: A high level driver for the Cassandra datastore

Database.Cassandra.JSON

Contents

Description

A higher level module for working with Cassandra.

Row and Column keys can be any string-like type implementing the CKey typeclass. You can add your own types by defining new instances

Serialization and de-serialization of Column values are taken care of automatically using the ToJSON and FromJSON typeclasses.

Also, this module currently attempts to reduce verbosity by throwing errors instead of returning Either types as in the Database.Cassandra.Basic module.

Synopsis

Connection

type CPool = Pool Cassandra ServerSource

A round-robin pool of cassandra connections

defServer :: ServerSource

A localhost server with default configuration

defServers :: [Server]Source

A single localhost server with default configuration

createCassandraPoolSource

Arguments

:: [Server]

List of servers to connect to

-> Int

Max connections per server (n)

-> NominalDiffTime

Kill each connection after this many seconds

-> KeySpace

Each pool operates on a single KeySpace

-> IO CPool 

Create a pool of connections to a cluster of Cassandra boxes

Each box in the cluster will get up to n connections. The pool will send queries in round-robin fashion to balance load on each box in the cluster.

Necessary Types

class CKey a whereSource

A typeclass to enable using any string-like type for row and column keys

data ModifyOperation a Source

Possible outcomes of a modify operation

Constructors

Update a 
Delete 
DoNothing 

Instances

Cassandra Operations

get :: (CKey rowKey, CKey colKey, FromJSON a) => CPool -> ColumnFamily -> rowKey -> Selector -> ConsistencyLevel -> IO [(colKey, a)]Source

An arbitrary get operation - slice with Selector.

Internally based on Basic.get. Table is assumed to be a regular ColumnFamily and contents of returned columns are cast into the target type.

getCol :: (CKey rowKey, CKey colKey, FromJSON a) => CPool -> ColumnFamily -> rowKey -> colKey -> ConsistencyLevel -> IO (Maybe a)Source

Get a single column from a single row

insertColSource

Arguments

:: (CKey rowKey, CKey colKey, ToJSON a) 
=> CPool 
-> ColumnFamily 
-> rowKey 
-> colKey 
-> ConsistencyLevel 
-> a

Content

-> IO () 

modifySource

Arguments

:: (CKey rowKey, CKey colKey, ToJSON a, FromJSON a) 
=> CPool 
-> ColumnFamily 
-> rowKey 
-> colKey 
-> ConsistencyLevel

Read quorum

-> ConsistencyLevel

Write quorum

-> (Maybe a -> IO (ModifyOperation a, b))

Modification function. Called with Just the value if present, Nothing otherwise.

-> IO b

Return the decided ModifyOperation and its execution outcome

A modify function that will fetch a specific column, apply modification function on it and save results back to Cassandra.

A b side value is returned for computational convenience.

This is intended to be a workhorse function, in that you should be able to do all kinds of relatively straightforward operations just using this function.

This method may throw a CassandraException for all exceptions other than NotFoundException.

modify_Source

Arguments

:: (CKey rowKey, CKey colKey, ToJSON a, FromJSON a) 
=> CPool 
-> ColumnFamily 
-> rowKey 
-> colKey 
-> ConsistencyLevel

Read quorum

-> ConsistencyLevel

Write quorum

-> (Maybe a -> IO (ModifyOperation a))

Modification function. Called with Just the value if present, Nothing otherwise.

-> IO () 

Same as modify but does not offer a side value.

This method may throw a CassandraException for all exceptions other than NotFoundException.

deleteSource

Arguments

:: CKey rowKey 
=> CPool

Cassandra connection

-> ColumnFamily

In ColumnFamily

-> rowKey

Key to be deleted

-> Selector

Columns to be deleted

-> ConsistencyLevel 
-> IO () 

Same as the delete in the Cassandra.Basic module, except that it throws an exception rather than returning an explicit Either value.