Safe Haskell | None |
---|
A Collection of utilities for binary packing values into Bytestring |
- class CasType a where
- encodeCas :: a -> ByteString
- decodeCas :: ByteString -> a
- newtype TAscii = TAscii {}
- newtype TBytes = TBytes {}
- newtype TCounter = TCounter {}
- newtype TInt32 = TInt32 {}
- newtype TInt64 = TInt64 {}
- newtype TUtf8 = TUtf8 {}
- newtype TUUID = TUUID {}
- newtype TLong = TLong {}
- newtype TTimeStamp = TTimeStamp {}
- toTimeStamp :: UTCTime -> TTimeStamp
- fromTimeStamp :: TTimeStamp -> UTCTime
- newtype Exclusive a = Exclusive a
- newtype Single a = Single a
- newtype SliceStart a = SliceStart a
Documentation
This typeclass defines and maps to haskell types that Cassandra natively knows about and uses in sorting and potentially validating column key values.
All column keys are eventually sent to and received from Cassandra in binary form. This typeclass allows us to map some Haskell type definitions to their binary representation. The correct binary serialization is handled for you behind the scenes.
For simplest cases, just use one of the string-like instances, e.g.
ByteString
, String
or Text
. Please keep in mind that these
are just mapped to untyped BytesType.
Remember that for special column types, such as TLong
, to have
any effect, your ColumnFamily must have been created with that
comparator or validator. Otherwise you're just encoding/decoding
integer values without any Cassandra support for sorting or
correctness.
The Python library pycassa has a pretty good tutorial to learn more.
Tuple instances support fixed ComponentType columns. Example:
insert "testCF" "row1" [packCol ((TLong 124, TAscii "Hello"), "some content")]
encodeCas :: a -> ByteStringSource
decodeCas :: ByteString -> aSource
CasType Int | Assumed to be a 64-bit Int and encoded as such. |
CasType Int32 | |
CasType Int64 | |
CasType String | |
CasType ByteString | |
CasType ByteString | |
CasType Text | |
CasType UTCTime | Via |
CasType Text | |
CasType Day | Encode days as |
CasType TTimeStamp | |
CasType TUtf8 | Encode and decode as Utf8 |
CasType TLong | Pack as an 8 byte unsigned number; negative signs are lost. Maps
to |
CasType TInt64 | Pack as an 8 byte number - same as |
CasType TInt32 | Pack as a 4 byte number |
CasType TCounter | |
CasType TBytes | |
CasType TAscii | |
(CasType a, CasType b) => CasType (SliceStart (a, b)) | Composite types - see Cassandra or pycassa docs to understand |
(CasType a, CasType b, CasType c) => CasType (SliceStart (a, b, c)) | |
(CasType a, CasType b, CasType c, CasType d) => CasType (SliceStart (a, b, c, d)) | |
CasType a => CasType (SliceStart (Single a)) | |
CasType a => CasType (Single a) | Use the |
CasType a => CasType (Exclusive (Single a)) | |
(CasType a, CasType b) => CasType (a, Exclusive b) | |
(CasType a, CasType b) => CasType (a, b) | Composite types - see Cassandra or pycassa docs to understand |
(CasType a, CasType b, CasType c) => CasType (a, b, Exclusive c) | |
(CasType a, CasType b, CasType c) => CasType (a, b, c) | |
(CasType a, CasType b, CasType c, CasType d) => CasType (a, b, c, Exclusive d) | |
(CasType a, CasType b, CasType c, CasType d) => CasType (a, b, c, d) |
newtype TTimeStamp Source
Timestamp that stores micro-seconds since epoch as TLong
underneath.
toTimeStamp :: UTCTime -> TTimeStampSource
Convert commonly used UTCTime
to TTimeStamp
.
First converts to seconds since epoch (POSIX seconds), then multiplies by a million and floors the resulting value. The value, therefore, is in micro-seconds and is accurate to within a microsecond.
Exclusive tag for composite column. You may tag the end of a composite range with this to make the range exclusive. See pycassa documentation for more information.
Eq a => Eq (Exclusive a) | |
Ord a => Ord (Exclusive a) | |
Read a => Read (Exclusive a) | |
Show a => Show (Exclusive a) | |
CasType a => CasType (Exclusive (Single a)) | |
(CasType a, CasType b) => CasType (a, Exclusive b) | |
(CasType a, CasType b, CasType c) => CasType (a, b, Exclusive c) | |
(CasType a, CasType b, CasType c, CasType d) => CasType (a, b, c, Exclusive d) |
Use the Single wrapper when you want to refer only to the first coolumn of a CompositeType column.
Single a |
Eq a => Eq (Single a) | |
Ord a => Ord (Single a) | |
Read a => Read (Single a) | |
Show a => Show (Single a) | |
CasType a => CasType (SliceStart (Single a)) | |
CasType a => CasType (Single a) | Use the |
CasType a => CasType (Exclusive (Single a)) |
newtype SliceStart a Source
Wrap your composite columns in this type when you're starting an inclusive column slice.
Eq a => Eq (SliceStart a) | |
Ord a => Ord (SliceStart a) | |
Read a => Read (SliceStart a) | |
Show a => Show (SliceStart a) | |
(CasType a, CasType b) => CasType (SliceStart (a, b)) | Composite types - see Cassandra or pycassa docs to understand |
(CasType a, CasType b, CasType c) => CasType (SliceStart (a, b, c)) | |
(CasType a, CasType b, CasType c, CasType d) => CasType (SliceStart (a, b, c, d)) | |
CasType a => CasType (SliceStart (Single a)) |