Created
December 22, 2012 16:53
-
-
Save anonymous/4359877 to your computer and use it in GitHub Desktop.
Problem putting JSON to riak via Haskell bindings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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