Skip to content
Browse files

Revert JSON and TimeSeries row type to ByteString

  • Loading branch information...
1 parent 5450deb commit 5d6d5af4a1188cf73f886fd1e5e6b55523855b00 @ozataman ozataman committed Aug 13, 2012
Showing with 21 additions and 18 deletions.
  1. +7 −15 src/Database/Cassandra/JSON.hs
  2. +14 −3 src/Database/Cassandra/Pack.hs
View
22 src/Database/Cassandra/JSON.hs
@@ -26,15 +26,15 @@ module Database.Cassandra.JSON
-- * Connection
CPool
- , Server (..)
+ , Server
, defServer
, defServers
- , KeySpace (..)
+ , KeySpace
, createCassandraPool
-- * MonadCassandra Typeclass
, MonadCassandra (..)
- , Cas (..)
+ , Cas
, runCas
-- * Cassandra Operations
@@ -51,7 +51,7 @@ module Database.Cassandra.JSON
, RowKey
, ColumnName
, ModifyOperation (..)
- , ColumnFamily (..)
+ , ColumnFamily
, ConsistencyLevel (..)
, CassandraException (..)
@@ -89,22 +89,13 @@ import qualified Data.Attoparsec as Atto (IResult(..), parse)
import qualified Data.ByteString.Char8 as B
import Data.ByteString.Lazy.Char8 (ByteString)
import qualified Data.ByteString.Lazy.Char8 as LB
-import Data.Int (Int32, Int64)
+import Data.Int (Int32)
import Data.Map (Map)
import qualified Data.Map as M
-import Data.Text (Text)
-import qualified Data.Text as T
-import qualified Data.Text.Encoding as T
-import qualified Data.Text.Lazy as LT
-import qualified Data.Text.Lazy.Encoding as LT
-import Network
import Prelude hiding (catch)
-------------------------------------------------------------------------------
import Database.Cassandra.Basic hiding (KeySelector(..), delete, get, getCol, getMulti)
import qualified Database.Cassandra.Basic as CB
-import Database.Cassandra.Pack
-import Database.Cassandra.Pool
-import Database.Cassandra.Types hiding (ColumnName, KeySelector(..))
-------------------------------------------------------------------------------
@@ -130,7 +121,7 @@ data ModifyOperation a =
-------------------------------------------------------------------------------
-type RowKey = Text
+type RowKey = ByteString
------------------------------------------------------------------------------
@@ -270,6 +261,7 @@ data KeySelector
-------------------------------------------------------------------------------
+ksToBasicKS :: KeySelector -> CB.KeySelector
ksToBasicKS (Keys k) = CB.Keys $ map toColKey k
ksToBasicKS (KeyRange ty fr to i) = CB.KeyRange ty (toColKey fr) (toColKey to) i
View
17 src/Database/Cassandra/Pack.hs
@@ -28,14 +28,11 @@ import Data.ByteString.Lazy.Char8 (ByteString)
import qualified Data.ByteString.Lazy.Char8 as LB
import Data.Char
import Data.Int
-import Data.List
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.Encoding as T
import qualified Data.Text.Lazy as LT
import qualified Data.Text.Lazy.Encoding as LT
-
-import Data.Time
-------------------------------------------------------------------------------
@@ -134,6 +131,9 @@ instance CasType TInt where
encodeCas = runPut . putWord64be . fromIntegral . getInt
decodeCas = TInt . fromIntegral . runGet getWord64be
+instance CasType Int where
+ encodeCas = encodeCas . TInt . fromIntegral
+ decodeCas = fromIntegral . getInt . decodeCas
-------------------------------------------------------------------------------
-- | Pack as an 8 byte unsigned number; negative signs are lost.
@@ -261,12 +261,14 @@ newtype Single a = Single a deriving (Eq,Show,Read,Ord)
-------------------------------------------------------------------------------
+putBytes :: B.ByteString -> Put
putBytes b = do
putLen b
putByteString b
-------------------------------------------------------------------------------
+getBytes' :: Get B.ByteString
getBytes' = getLen >>= getBytes
@@ -282,7 +284,12 @@ putLen b = putWord16be . fromIntegral $ (B.length b)
-------------------------------------------------------------------------------
+toStrict :: ByteString -> B.ByteString
toStrict = B.concat . LB.toChunks
+
+
+-------------------------------------------------------------------------------
+fromStrict :: B.ByteString -> ByteString
fromStrict = LB.fromChunks . return
@@ -295,16 +302,20 @@ getSegment = do
-------------------------------------------------------------------------------
+putSegment :: CasType a => a -> PutM b -> PutM b
putSegment a f = do
putBytes . toStrict $ encodeCas a
f
-- | When end point is exclusive
+exc :: Put
exc = putWord8 . fromIntegral $ ord '\xff'
-- | Regular (inclusive) end point
+end :: Put
end = putWord8 . fromIntegral $ ord '\x01'
-- | Separator between composite parts
+sep :: Put
sep = putWord8 . fromIntegral $ ord '\x00'

0 comments on commit 5d6d5af

Please sign in to comment.
Something went wrong with that request. Please try again.