1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
-- | Keep is a database built on Data.Acid.
--
-- If this proves useful, maybe we could make it a more general thing. Like
-- `Biz.Keep`. I could wrap all the safecopy stuff in my own template haskell
-- like `$(keep ''MyType)`.
--
module Biz.Ibb.Keep where
import Biz.Ibb.Core (Person(..), Book(..))
import Data.SafeCopy
import Data.Data (Data, Typeable)
import Data.Text (Text)
import Data.IxSet (Indexable(..), ixFun, ixSet)
-- * Index @Person@
$(deriveSafeCopy 0 'base ''Person)
newtype PersonName =
PersonName Text deriving (Eq, Ord, Data, Typeable)
newtype PersonBlurb =
PersonBlurb Text deriving (Eq, Ord, Data, Typeable)
instance Indexable Person where
empty = ixSet
[ ixFun $ \p -> [ PersonName $ _name p ]
, ixFun $ \p -> [ _pic p ]
, ixFun $ \p -> [ _twitter p ]
, ixFun $ \p -> [ _website p ]
, ixFun $ \p -> [ _books p ]
, ixFun $ \p -> [ PersonBlurb $ _blurb p ]
]
-- * Index @Book@
$(deriveSafeCopy 0 'base ''Book)
newtype BookTitle =
BookTitle Text deriving (Eq, Ord, Data, Typeable)
newtype BookAuthor =
BookAuthor Text deriving (Eq, Ord, Data, Typeable)
instance Indexable Book where
empty = ixSet
[ ixFun $ \b -> [ BookTitle $ _title b ]
, ixFun $ \b -> [ BookAuthor $ _author b ]
, ixFun $ \b -> [ _amznref b ]
]
|