Safe Haskell | Safe-Infered |
---|
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.
- type CPool = Pool Cassandra
- type Server = (HostName, Int)
- defServer :: Server
- defServers :: [Server]
- type KeySpace = String
- createCassandraPool :: [Server] -> Int -> Int -> NominalDiffTime -> KeySpace -> IO CPool
- class MonadIO m => MonadCassandra m where
- getCassandraPool :: m CPool
- newtype Cas a = Cas {}
- runCas :: Cas a -> CPool -> IO a
- get :: (MonadCassandra m, FromJSON a) => ColumnFamily -> RowKey -> Selector -> ConsistencyLevel -> m [(ColumnName, a)]
- getCol :: (MonadCassandra m, FromJSON a) => ColumnFamily -> RowKey -> ColumnName -> ConsistencyLevel -> m (Maybe a)
- getMulti :: (MonadCassandra m, FromJSON a) => ColumnFamily -> KeySelector -> Selector -> ConsistencyLevel -> m (Map RowKey [(ColumnName, a)])
- insertCol :: (MonadCassandra m, ToJSON a) => ColumnFamily -> RowKey -> ColumnName -> ConsistencyLevel -> a -> m ()
- modify :: (MonadCassandra m, ToJSON a, FromJSON a) => ColumnFamily -> RowKey -> ColumnName -> ConsistencyLevel -> ConsistencyLevel -> (Maybe a -> m (ModifyOperation a, b)) -> m b
- modify_ :: (MonadCassandra m, ToJSON a, FromJSON a) => ColumnFamily -> RowKey -> ColumnName -> ConsistencyLevel -> ConsistencyLevel -> (Maybe a -> m (ModifyOperation a)) -> m ()
- delete :: MonadCassandra m => ColumnFamily -> RowKey -> Selector -> ConsistencyLevel -> m ()
- type RowKey = Text
- type ColumnName = ByteString
- data ModifyOperation a
- type ColumnFamily = String
- data ConsistencyLevel
- = ONE
- | QUORUM
- | LOCAL_QUORUM
- | EACH_QUORUM
- | ALL
- | ANY
- | TWO
- | THREE
- data CassandraException
- data Selector
- = All
- | ColNames [ColumnName]
- | SupNames ColumnName [ColumnName]
- | Range (Maybe ColumnName) (Maybe ColumnName) Order Int32
- data KeySelector
- data KeyRangeType
- class CKey a where
- toBS :: a -> ByteString
- fromBS :: ByteString -> a
- packLong :: Integral a => a -> ByteString
Connection
defServers :: [Server]Source
A single localhost server with default configuration
:: [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
CassandraException
s at any point in time.
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.
:: (MonadCassandra m, ToJSON a) | |
=> ColumnFamily | |
-> RowKey | |
-> ColumnName | |
-> ConsistencyLevel | |
-> a | Content |
-> m () |
:: (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 |
-> m b | Return the decided |
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
.
:: (MonadCassandra m, ToJSON a, FromJSON a) | |
=> ColumnFamily | |
-> RowKey | |
-> ColumnName | |
-> ConsistencyLevel | Read quorum |
-> ConsistencyLevel | Write quorum |
-> (Maybe a -> m (ModifyOperation a)) | Modification function. Called with |
-> m () |
Same as modify
but does not offer a side value.
This method may throw a CassandraException
for all exceptions other than
NotFoundException
.
:: MonadCassandra m | |
=> ColumnFamily | In |
-> RowKey | Key to be deleted |
-> Selector | Columns to be deleted |
-> ConsistencyLevel | |
-> m () |
Necessary Types
type ColumnName = ByteStringSource
data ModifyOperation a Source
Possible outcomes of a modify operation
Eq a => Eq (ModifyOperation a) | |
Ord a => Ord (ModifyOperation a) | |
Read a => Read (ModifyOperation a) | |
Show a => Show (ModifyOperation a) |
type ColumnFamily = StringSource
data ConsistencyLevel
data CassandraException 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
.
All | Return everything in |
ColNames [ColumnName] | Return specific columns or super-columns depending on the |
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 |
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.
Helpers
A typeclass to enable using any string-like type for row and column keys
toBS :: a -> ByteStringSource
fromBS :: ByteString -> aSource
packLong :: Integral a => a -> ByteStringSource
Pack any integral value into LongType