Permalink
Browse files

Add Single wrapper

  • Loading branch information...
ozataman committed Aug 11, 2012
1 parent e1313d7 commit 2325e02f4af990b29bd2ad04319480615ba3487d
Showing with 20 additions and 0 deletions.
  1. +20 −0 src/Database/Cassandra/Pack.hs
@@ -15,6 +15,7 @@ module Database.Cassandra.Pack
, TUUID (..)
, TLong (..)
, Exclusive (..)
+ , Single (..)
) where
-------------------------------------------------------------------------------
@@ -148,6 +149,15 @@ instance CasType TUtf8 where
decodeCas = TUtf8 . T.decodeUtf8 . B.concat . LB.toChunks
+-------------------------------------------------------------------------------
+-- | Use the 'Single' wrapper when querying only with the first of a
+-- two or more field CompositeType.
+instance (CasType a) => CasType (Single a) where
+ encodeCas a = runPut $ do
+ putSegment a end
+
+ decodeCas bs = flip runGet bs $ Single <$> getSegment
+
-------------------------------------------------------------------------------
-- | Composite types - see Cassandra or pycassa docs to understand
instance (CasType a, CasType b) => CasType (a,b) where
@@ -228,9 +238,19 @@ instance CasType a => CasType [a] where
putSegment (last as) end
+-------------------------------------------------------------------------------
+-- | 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.
newtype Exclusive a = Exclusive a deriving (Eq,Show,Read,Ord)
+-------------------------------------------------------------------------------
+-- | Use the Single wrapper when you want to refer only to the first
+-- coolumn of a CompositeType column.
+newtype Single a = Single a deriving (Eq,Show,Read,Ord)
+
+
-- | composite columns are a pain
-- need to write 2 byte length, n byte body, 1 byte separator
--

0 comments on commit 2325e02

Please sign in to comment.