Database.Cassandra.Basic
- 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
- data Selector
- = All
- | ColNames [ColumnName]
- | SupNames ColumnName [ColumnName]
- | Range (Maybe ColumnName) (Maybe ColumnName) Order Int32
- data Order
- data KeySelector
- data KeyRangeType
- data CassandraException
- type CPool = Pool Cassandra Server
- type Server = (HostName, PortID)
- defServer :: Server
- defServers :: [Server]
- type KeySpace = String
- createCassandraPool :: [Server] -> Int -> NominalDiffTime -> KeySpace -> IO CPool
- getCol :: CPool -> ColumnFamily -> Key -> ColumnName -> ConsistencyLevel -> IO (Either CassandraException Column)
- get :: CPool -> ColumnFamily -> Key -> Selector -> ConsistencyLevel -> IO (Either CassandraException Row)
- getMulti :: CPool -> ColumnFamily -> KeySelector -> Selector -> ConsistencyLevel -> IO (Either CassandraException (Map ByteString Row))
- insert :: CPool -> ColumnFamily -> Key -> ConsistencyLevel -> Row -> IO (Either CassandraException ())
- delete :: CPool -> ColumnFamily -> Key -> Selector -> ConsistencyLevel -> IO (Either CassandraException ())
- getTime :: IO Int64
- throwing :: IO (Either CassandraException a) -> IO a
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
Constructors
| SuperColumn ColumnName [Column] | |
| Column | |
col :: ByteString -> ByteString -> ColumnSource
A short-hand for creating key-value Column values
data ConsistencyLevel
Constructors
| ONE | |
| QUORUM | |
| LOCAL_QUORUM | |
| EACH_QUORUM | |
| ALL | |
| ANY | |
| TWO | |
| THREE |
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.
Constructors
| 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.
Constructors
| Keys [Key] | Just a list of keys to get |
| KeyRange KeyRangeType Key Key Int32 | A range of keys to get. Remember that RandomPartitioner ranges may not mean much as keys are randomly assigned to nodes. |
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
Exceptions
data CassandraException Source
Connection
defServers :: [Server]Source
A single localhost server with default configuration
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.
Cassandra Operations
Arguments
| :: CPool | |
| -> ColumnFamily | |
| -> Key | Row key |
| -> ColumnName | Column/SuperColumn name |
| -> ConsistencyLevel | Read quorum |
| -> IO (Either CassandraException Column) |
Get a single key-column value
Arguments
| :: CPool | |
| -> ColumnFamily | in ColumnFamily |
| -> Key | Row key to get |
| -> Selector | Slice columns with selector |
| -> ConsistencyLevel | |
| -> IO (Either CassandraException Row) |
An arbitrary get operation - slice with Selector
Arguments
| :: CPool | |
| -> ColumnFamily | |
| -> KeySelector | A selection of rows to fetch in one hit |
| -> Selector | Subject to column selector conditions |
| -> ConsistencyLevel | |
| -> IO (Either CassandraException (Map ByteString Row)) | A Map from Row keys to |
Do multiple gets in one DB hit
insert :: CPool -> ColumnFamily -> Key -> ConsistencyLevel -> Row -> IO (Either CassandraException ())Source
Insert an entire row into the db.
This will do as many round-trips as necessary to insert the full row.
Arguments
| :: CPool | |
| -> ColumnFamily | In |
| -> Key | Key to be deleted |
| -> Selector | Columns to be deleted |
| -> ConsistencyLevel | |
| -> IO (Either CassandraException ()) |
Delete an entire row, specific columns or a specific sub-set of columns within a SuperColumn.
Utility
Cassandra is VERY sensitive to its timestamp values. As a convention, timestamps are always in microseconds