Stability | experimental |
---|---|
Maintainer | Ozgun Ataman |
Safe Haskell | None |
Low-level functionality for working with Cassandra at the most basic level.
- 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
- type Cas a = ReaderT CPool IO a
- runCas :: CPool -> Cas a -> IO a
- transCas :: MonadCassandra m => Cas a -> m (IO a)
- mapCassandra :: (Traversable t, MonadCassandra m) => t (Cas b) -> m (t b)
- getCol :: (MonadCassandra m, CasType k) => ColumnFamily -> ByteString -> k -> ConsistencyLevel -> m (Maybe Column)
- get :: MonadCassandra m => ColumnFamily -> ByteString -> Selector -> ConsistencyLevel -> m [Column]
- getMulti :: MonadCassandra m => ColumnFamily -> KeySelector -> Selector -> ConsistencyLevel -> m (Map ByteString Row)
- insert :: MonadCassandra m => ColumnFamily -> ByteString -> ConsistencyLevel -> [Column] -> m ()
- delete :: MonadCassandra m => ColumnFamily -> Key -> Selector -> ConsistencyLevel -> m ()
- retryCas :: (MonadCatch m, MonadIO m) => RetryPolicy -> m a -> m a
- casRetryH :: Monad m => Int -> Handler m Bool
- networkRetryH :: Monad m => Int -> Handler m Bool
- data Selector
- range :: Selector
- boundless :: Maybe ByteString
- data Order
- reverseOrder :: Order -> Order
- data KeySelector
- data KeyRangeType
- data CassandraException
- getTime :: IO Int64
- throwing :: IO (Either CassandraException a) -> IO a
- wrapException :: IO a -> IO a
- type ColumnFamily = String
- type Key = ByteString
- type ColumnName = ByteString
- type Value = ByteString
- data Column
- = SuperColumn ColumnName [Column]
- | Column { }
- col :: ByteString -> ByteString -> Column
- packCol :: CasType k => (k, ByteString) -> Column
- unpackCol :: CasType k => Column -> (k, Value)
- packKey :: CasType a => a -> ByteString
- type Row = [Column]
- data ConsistencyLevel
- = ONE
- | QUORUM
- | LOCAL_QUORUM
- | EACH_QUORUM
- | ALL
- | ANY
- | TWO
- | THREE
- class CKey a where
- toColKey :: a -> ByteString
- fromColKey :: ByteString -> Either String a
- fromColKey' :: CKey a => ByteString -> a
- module Database.Cassandra.Pack
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.
MonadIO m => MonadCassandra (ReaderT CPool m) |
transCas :: MonadCassandra m => Cas a -> m (IO a)Source
Unwrap a Cassandra action and return an IO continuation that can then be run in a pure IO context.
This is useful when you design all your functions in a generic form
with MonadCassandra
m constraints and then one day need to feed
your function to a utility that can only run in an IO context. This
function is then your friendly utility for extracting an IO action.
mapCassandra :: (Traversable t, MonadCassandra m) => t (Cas b) -> m (t b)Source
Run a list of cassandra computations in parallel using the async library
Cassandra Operations
:: (MonadCassandra m, CasType k) | |
=> ColumnFamily | |
-> ByteString | Row key |
-> k | Column/SuperColumn key; see |
-> ConsistencyLevel | Read quorum |
-> m (Maybe Column) |
Get a single key-column value.
:: MonadCassandra m | |
=> ColumnFamily | in ColumnFamily |
-> ByteString | Row key to get |
-> Selector | Slice columns with selector |
-> ConsistencyLevel | |
-> m [Column] |
An arbitrary get operation - slice with Selector
:: MonadCassandra m | |
=> ColumnFamily | |
-> KeySelector | A selection of rows to fetch in one hit |
-> Selector | Subject to column selector conditions |
-> ConsistencyLevel | |
-> m (Map ByteString Row) | A Map from Row keys to |
Do multiple get
s in one DB hit
:: MonadCassandra m | |
=> ColumnFamily | |
-> ByteString | Row key |
-> ConsistencyLevel | |
-> [Column] | best way to make these columns is through packCol |
-> m () |
Insert an entire row into the db.
This will do as many round-trips as necessary to insert the full row. Please keep in mind that each column and each column of each super-column is sent to the server one by one.
insert "testCF" "row1" ONE [packCol ("column key", "some column content")]
:: MonadCassandra m | |
=> ColumnFamily | In |
-> Key | Key to be deleted |
-> Selector | Columns to be deleted |
-> ConsistencyLevel | |
-> m () |
Delete an entire row, specific columns or a specific sub-set of columns within a SuperColumn.
Retrying Queries
:: (MonadCatch m, MonadIO m) | |
=> RetryPolicy | For default settings, just use |
-> m a | Action to perform |
-> m a |
retrying
with direct cassandra support. Server-related failures
will be retried.
UnavailableException
, TimedOutException
and
SchemaDisagreementException
will be automatically retried.
casRetryH :: Monad m => Int -> Handler m BoolSource
Exception handler that returns True
for errors that may be
resolved after a retry. So they are good candidates for retrying
queries.
networkRetryH :: Monad m => Int -> Handler m BoolSource
IOException
s should be retried
Filtering
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
.
Column names and ranges are specified by any type that can be
packed into a Cassandra column using the CasType
typeclass.
All | Return everything in |
forall a . CasType a => ColNames [a] | Return specific columns or super-columns depending on the |
forall a b . (CasType a, CasType b) => SupNames a [b] | When deleting specific columns in a super column |
forall a b . (CasType a, CasType b) => Range | Return a range of columns or super-columns. |
|
A default starting point for range Selector
. Use this so you
don't run into ambiguous type variables when using Nothing.
range = Range (Nothing :: Maybe ByteString) (Nothing :: Maybe ByteString) Regular 1024
reverseOrder :: Order -> OrderSource
data KeySelector Source
A Key
range selector to use with getMulti
.
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.
Exceptions
data CassandraException Source
Utility
Cassandra is VERY sensitive to its timestamp values. As a convention, timestamps are always in microseconds
wrapException :: IO a -> IO aSource
Wrap exceptions of the underlying thrift library into the exception types defined here.
Basic Types
type ColumnFamily = StringSource
type Key = ByteStringSource
type ColumnName = ByteStringSource
type Value = ByteStringSource
A Column is either a single key-value pair or a SuperColumn with an arbitrary number of key-value pairs
col :: ByteString -> ByteString -> ColumnSource
A short-hand for creating key-value Column
values. This is
pretty low level; you probably want to use packCol
.
packCol :: CasType k => (k, ByteString) -> ColumnSource
Pack key-value pair into Column
form ready to be written to Cassandra
unpackCol :: CasType k => Column -> (k, Value)Source
Unpack a Cassandra Column
into a more convenient (k,v) form
packKey :: CasType a => a -> ByteStringSource
Pack a column key into binary, ready for submission to Cassandra
data ConsistencyLevel
Helpers
A typeclass to enable using any string-like type for row and column keys
toColKey :: a -> ByteStringSource
fromColKey :: ByteString -> Either String aSource
CKey String | |
CKey ByteString | |
CKey ByteString | |
CKey Text | |
CKey Text | |
CKey [ByteString] | For easy composite keys, just serialize your data type to a list of bytestrings, we'll concat them and turn them into column keys. |
fromColKey' :: CKey a => ByteString -> aSource
Raise an error if conversion fails
Cassandra Column Key Types
module Database.Cassandra.Pack