Created
January 4, 2013 03:44
-
-
Save wavewave/4449726 to your computer and use it in GitHub Desktop.
Simplest example of using haskell CouchDB
This file contains hidden or 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 DeriveDataTypeable, ScopedTypeVariables #-} | |
| import Database.CouchDB | |
| import Text.JSON | |
| import Text.JSON.Pretty | |
| import Text.JSON.Generic | |
| data BookData = BookData { title :: String, author :: String } | |
| deriving (Show, Typeable, Data) | |
| ppJSON = putStrLn . render . pp_value | |
| testdb = db "test" | |
| data1 = BookData "my book" "me" | |
| data2 = BookData "your book" "you" | |
| data1json = toJSON data1 | |
| main :: IO () | |
| main = do | |
| (doc1,rev1)<- runCouchDB' (newDoc testdb data1json) | |
| print (doc1,rev1) | |
| Just (_,_,jvalue) <- runCouchDB' (getDoc testdb doc1) | |
| ppJSON jvalue | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment