Safe Haskell | None |
---|
- 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
- getCol :: MonadCassandra m => ColumnFamily -> Key -> ColumnName -> ConsistencyLevel -> m (Maybe Column)
- get :: MonadCassandra m => ColumnFamily -> Key -> Selector -> ConsistencyLevel -> m Row
- getMulti :: MonadCassandra m => ColumnFamily -> KeySelector -> Selector -> ConsistencyLevel -> m (Map ByteString Row)
- insert :: MonadCassandra m => ColumnFamily -> Key -> ConsistencyLevel -> Row -> m ()
- delete :: MonadCassandra m => ColumnFamily -> Key -> Selector -> ConsistencyLevel -> m ()
- data Selector
- = All
- | ColNames [ColumnName]
- | SupNames ColumnName [ColumnName]
- | Range (Maybe ColumnName) (Maybe ColumnName) Order Int32
- data 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
- type Row = [Column]
- data ConsistencyLevel
- = ONE
- | QUORUM
- | LOCAL_QUORUM
- | EACH_QUORUM
- | ALL
- | ANY
- | TWO
- | THREE
- 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
:: MonadCassandra m | |
=> ColumnFamily | |
-> Key | Row key |
-> ColumnName | Column/SuperColumn name |
-> ConsistencyLevel | Read quorum |
-> m (Maybe Column) |
Get a single key-column value.
:: MonadCassandra m | |
=> ColumnFamily | in ColumnFamily |
-> Key | Row key to get |
-> Selector | Slice columns with selector |
-> ConsistencyLevel | |
-> m Row |
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
insert :: MonadCassandra m => ColumnFamily -> Key -> ConsistencyLevel -> Row -> m ()Source
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.
:: 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.
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
.
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 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
data ConsistencyLevel
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