https://github.com/owainlewis/cloudant-hs
Haskell client for IBM Cloudant
https://github.com/owainlewis/cloudant-hs
cloudant couchdb database haskell haskell-library
Last synced: 4 days ago
JSON representation
Haskell client for IBM Cloudant
- Host: GitHub
- URL: https://github.com/owainlewis/cloudant-hs
- Owner: owainlewis
- License: other
- Created: 2015-05-21T10:46:56.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2026-07-05T20:32:12.000Z (10 days ago)
- Last Synced: 2026-07-05T22:11:16.608Z (10 days ago)
- Topics: cloudant, couchdb, database, haskell, haskell-library
- Language: Haskell
- Homepage:
- Size: 74.2 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Cloudant

This package provides a Haskell interface to the IBM Cloudant database.
It should also have full compatibility with CouchDB
## Configuration
The configuration needed for Cloudant is fairly minimal. We need
1. The full host name of your database (e.g https://owainlewis.cloudant.com)
2. An API Key which is made up of a username and password
```haskell
-- Remote cloudant config
conf :: Config
conf = Config "https://owainlewis.cloudant.com" $ ApiKey "USER" "PASS"
-- Local configuration for testing against CouchDB
localConfig :: Config
localConfig = Config "http://192.168.59.103" $ ApiKey "admin" "password"
```
## Return types
All responses are in the form **IO (Either Error Response)**
## Example
```haskell
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE OverloadedStrings #-}
module Example where
import Data.Aeson
import qualified Data.ByteString.Lazy as LBS
import GHC.Generics (Generic)
import Network.Cloudant.Core as Cloudant
import Network.Cloudant.Util (localConfig)
data Customer = Customer {
firstName :: String
, lastName :: String
, email :: String
} deriving ( Show, Generic )
instance ToJSON Customer
instance FromJSON Customer
customer1 :: Customer
customer1 = Customer "Jack" "Dorsey" "jack@twitter.com"
asJSON :: ToJSON s => s -> LBS.ByteString
asJSON customer = encode . toJSON $ customer
-- Create a new database
Cloudant.createDatabase localconfig "customers"
-- Add a document to the database
-- This will automatically serialize any document type with a ToJSON instance
-- The signature for createDocument is
-- createDocument :: ToJSON a => Config -> String -> a -> IO (Either String TF.OKResponse)
Cloudant.createDocument localConfig "customers" (Customer "Jack" "Dorsey" "jack@twitter.com")
```
## Database Info
```haskell
λ> databaseInfo localConfig "customers"
Right (DatabaseInfo {dbName = "customers", documentCount = 3, diskSize = 16482})
```