Created
August 21, 2014 21:47
-
-
Save zerokarmaleft/6a1c07257ba1d0a796cc to your computer and use it in GitHub Desktop.
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 OverloadedStrings, ScopedTypeVariables, DeriveGeneric #-} | |
module Main where | |
import Data.Aeson.Types | |
import qualified Data.ByteString.Lazy as BSL | |
import qualified Data.ByteString.UTF8 as UTF8 | |
import GHC.Generics | |
import Network.Riak | |
data Book = Book | |
{ isbn :: String | |
, title :: String | |
, author :: String | |
, body :: String | |
, copies_owned :: Int | |
} deriving (Show, Generic) | |
instance ToJSON Book | |
instance FromJSON Book | |
instance Resolvable Book where | |
resolve = const | |
instance Resolvable Int where | |
resolve = const | |
book = Book | |
{ isbn = "1111979723" | |
, title = "Moby Dick" | |
, author = "Herman Melville" | |
, body = "Call me Ishmael. Some years ago..." | |
, copies_owned = 3 | |
} | |
main :: IO () | |
main = | |
do conn <- connect defaultClient | |
val1 <- get conn "test" "two" Default | |
case val1 of | |
Just (c :: Book, vc) -> putStrLn $ "Key was found: " ++ show c | |
Nothing -> putStrLn "Key was not found" | |
val2 <- get conn "test" "one" Default | |
case val2 of | |
Just (c :: Int, vc) -> putStrLn $ "Key was found: " ++ show c | |
Nothing -> putStrLn "Key was not found" | |
disconnect conn |
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
Key was found: Book {isbn = "111979723", title = "Moby Dick", author = "Herman Melville", body = "Call me Ishmael. Some years ago...", copies_owned = 3} | |
example: Riak type error (Network.Riak.Value.convert): 1 values failed conversion: [Content {value = "1", content_type = Just "application/json", charset = Nothing, content_encoding = Nothing, vtag = Just "3p4hJTKso95LvFLdDpkc2J", links = fromList [], last_mod = Just 1408572574, last_mod_usecs = Just 536017, usermeta = fromList [], indexes = fromList []}] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment