Skip to content

Instantly share code, notes, and snippets.

Created December 22, 2012 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4359877 to your computer and use it in GitHub Desktop.
Save anonymous/4359877 to your computer and use it in GitHub Desktop.
Problem putting JSON to riak via Haskell bindings
{-# LANGUAGE ScopedTypeVariables, OverloadedStrings #-}
import Network.Riak
import qualified Network.Riak.JSON as RiakJSON
import Network.Riak.Connection.Pool
import qualified Data.ByteString.Lazy.Char8 as B
import Control.Applicative
import qualified Data.Aeson as JSON
testPut :: IO ()
testPut = do
pool <- create defaultClient 1 1 2
withConnection pool myPut >>= \(_,vclock) -> print vclock
where
myPut conn = do
(bs::B.ByteString) <- (JSON.encode . B.pack) <$> readFile "json.dat"
RiakJSON.put conn "bucketFoo" "keyFoo" Nothing bs Default Default
{- ghci complaint
*Main> testPut
*** Exception: Riak type error (Network.Riak.Value.convert): 1 values failed conversion: [Content {value = "\"\\\"{\\\\n \\\\\\\"firstName\\\\\\\": \\\\\\\"John\\\\\\\",\\\\n \\\\\\\"lastName\\\\\\\": \\\\\\\"Smith\\\\\\\" \\\\n }\\\\n\\\"\"", content_type = Just "application/json", charset = Nothing, content_encoding = Nothing, vtag = Just "gokFoPe2aLYM3QEiBYNyc", links = fromList [], last_mod = Just 1356195100, last_mod_usecs = Just 148285, usermeta = fromList [], indexes = fromList []}]
-}
{- json.dat file
{
"firstName": "John",
"lastName": "Smith"
}
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment