gdritter repos tansu-berkeleydb / master

Tree @master (Download .tar.gz) @masterview markup · raw · history · blame


WARNING: DO NOT USE THIS LIBRARY. Like, seriously, there are a ton of other storage libraries that aren't fly-by-night like this one.

This is a backend for the tansu library that supports storing and retrieving data using the Berkeley DB library. Be aware that Berkeley DB, and therefore this code as well, is GPL-licensed, and thus cannot be used in commercial products.


{-# LANGUAGE DeriveGeneric, DeriveAnyClass #-}

module Main where

import Data.Serialize (Serialize)
import GHC.Generics (Generic)

import Database.Tansu ((=:), get, run)
import Database.Tansu.Backend.BerkeleyDb (withBerkeleyDb)

data Person = Person { name :: String, age  :: Int }
  deriving (Eq, Show, Generic, Serialize)

main :: IO ()
main = withBerkeleyDb "sample.db" $ \ db -> do
  run db $ do
    "alex"  =: Person "alex" 33
    "blake" =: Person "blake" 22

  Right age <- run db (age `fmap` get "blake")
  putStrLn $ "Blake's age is " ++ show age


Please see the corresponding section of the tansu library page.