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

Safe HaskellSafe-Infered

Database.Cassandra.JSON

Contents

Description

A higher level module for working with Cassandra.

All row and column keys are standardized to be of strict types. Row keys are Text, while Column keys are ByteString. This might change in the future and we may revert to entirely ByteString keys.

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

Synopsis

Connection

type CPool = Pool CassandraSource

A round-robin pool of cassandra connections

type Server = (HostName, Int)Source

A (ServerName, Port) tuple

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

Number of stripes to maintain

-> Int

Max connections per stripe

-> 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.

MonadCassandra Typeclass

class MonadIO m => MonadCassandra m whereSource

All Cassy operations are designed to run inside MonadCassandra context.

We provide a default concrete Cas datatype, but you can simply make your own application monads an instance of MonadCassandra for conveniently using all operations of this package.

Please keep in mind that all Cassandra operations may raise CassandraExceptions at any point in time.

Instances

newtype Cas a Source

Constructors

Cas 

Fields

unCas :: ReaderT CPool IO a
 

runCas :: Cas a -> CPool -> IO aSource

Main running function when using the ad-hoc Cas monad. Just write your cassandra actions within the Cas monad and supply them with a CPool to execute.

Cassandra Operations

get :: (MonadCassandra m, FromJSON a) => ColumnFamily -> RowKey -> Selector -> ConsistencyLevel -> m [(ColumnName, 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 :: (MonadCassandra m, FromJSON a) => ColumnFamily -> RowKey -> ColumnName -> ConsistencyLevel -> m (Maybe a)Source

Get a single column from a single row

getMulti :: (MonadCassandra m, FromJSON a) => ColumnFamily -> KeySelector -> Selector -> ConsistencyLevel -> m (Map RowKey [(ColumnName, a)])Source

Get a slice of columns from multiple rows at once. Note that since we are auto-serializing from JSON, all the columns must be of the same data type.

insertColSource

Arguments

:: (MonadCassandra m, ToJSON a) 
=> ColumnFamily 
-> RowKey 
-> ColumnName 
-> ConsistencyLevel 
-> a

Content

-> m () 

modifySource

Arguments

:: (MonadCassandra m, ToJSON a, FromJSON a) 
=> ColumnFamily 
-> RowKey 
-> ColumnName 
-> ConsistencyLevel

Read quorum

-> ConsistencyLevel

Write quorum

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

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

-> m 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

:: (MonadCassandra m, ToJSON a, FromJSON a) 
=> ColumnFamily 
-> RowKey 
-> ColumnName 
-> ConsistencyLevel

Read quorum

-> ConsistencyLevel

Write quorum

-> (Maybe a -> m (ModifyOperation a))

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

-> m () 

Same as modify but does not offer a side value.

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

deleteSource

Arguments

:: MonadCassandra m 
=> ColumnFamily

In ColumnFamily

-> RowKey

Key to be deleted

-> Selector

Columns to be deleted

-> ConsistencyLevel 
-> m () 

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

Necessary Types

data ModifyOperation a Source

Possible outcomes of a modify operation

Constructors

Update a 
Delete 
DoNothing 

Instances

data Selector Source

A column selector/filter statement for queries.

Remember that SuperColumns are always fully deserialized, so we don't offer a way to filter columns within a SuperColumn.

Constructors

All

Return everything in Row

ColNames [ColumnName]

Return specific columns or super-columns depending on the ColumnFamily

SupNames ColumnName [ColumnName]

When deleting specific columns in a super column

Range (Maybe ColumnName) (Maybe ColumnName) Order Int32

Return a range of columns or super-columns

Instances

data KeyRangeType Source

Encodes the Key vs. Token options in the thrift API.

InclusiveRange ranges are just plain intuitive range queries. WrapAround ranges are also inclusive, but they wrap around the ring.

Constructors

InclusiveRange 
WrapAround 

Instances

Helpers

class CKey a whereSource

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

packLong :: Integral a => a -> ByteStringSource

Pack any integral value into LongType