Skip to content

Instantly share code, notes, and snippets.

@wavewave
Created January 4, 2013 03:44
Show Gist options
  • Select an option

  • Save wavewave/4449726 to your computer and use it in GitHub Desktop.

Select an option

Save wavewave/4449726 to your computer and use it in GitHub Desktop.
Simplest example of using haskell CouchDB
{-# 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