]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Types.hs
[DEP] haskell-opaleye dep upgrade
[gargantext.git] / src / Gargantext / Database / Types.hs
1 {-|
2 Module : Gargantext.Database.Types
3 Description : Specific Types to manage core Gargantext type with database
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10 -}
11
12 {-# LANGUAGE TemplateHaskell #-}
13
14 module Gargantext.Database.Types
15 where
16
17 import Data.Hashable (Hashable)
18 import Gargantext.Core.Text (HasText(..))
19 import Gargantext.Database.Schema.Prelude
20 import Gargantext.Prelude
21 import qualified Database.PostgreSQL.Simple as PGS
22
23
24 -- | Index memory of any type in Gargantext
25 data Indexed i a =
26 Indexed { _index :: !i
27 , _unIndex :: !a
28 }
29 deriving (Show, Generic, Eq, Ord)
30
31 makeLenses ''Indexed
32
33 ----------------------------------------------------------------------
34 -- | Main instances
35 instance (FromField i, FromField a) => PGS.FromRow (Indexed i a) where
36 fromRow = Indexed <$> field <*> field
37
38 instance HasText a => HasText (Indexed i a)
39 where
40 hasText (Indexed _ a) = hasText a
41
42 instance (Hashable a, Hashable b) => Hashable (Indexed a b)