]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Types.hs
[TOOLS] repoSize and renaming
[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 {-# OPTIONS_GHC -fno-warn-orphans #-}
13 {-# LANGUAGE TemplateHaskell #-}
14
15 module Gargantext.Database.Types
16 where
17
18 import Data.Hashable (Hashable)
19 import Gargantext.Core.Text (HasText(..))
20 import Gargantext.Database.Schema.Prelude
21 import Gargantext.Prelude
22 import qualified Database.PostgreSQL.Simple as PGS
23
24
25 -- | Index memory of any type in Gargantext
26 data Indexed i a =
27 Indexed { _index :: !i
28 , _unIndex :: !a
29 }
30 deriving (Show, Generic, Eq, Ord)
31
32 makeLenses ''Indexed
33
34 ----------------------------------------------------------------------
35 -- | Main instances
36 instance (FromField i, FromField a) => PGS.FromRow (Indexed i a) where
37 fromRow = Indexed <$> field <*> field
38
39 instance HasText a => HasText (Indexed i a)
40 where
41 hasText (Indexed _ a) = hasText a
42
43 instance (Hashable a, Hashable b) => Hashable (Indexed a b)
44
45 instance DefaultFromField (Nullable SqlInt4) Int where
46 defaultFromField = fromPGSFromField
47
48 instance DefaultFromField (Nullable SqlFloat8) Int where
49 defaultFromField = fromPGSFromField
50
51 instance DefaultFromField (Nullable SqlFloat8) Double where
52 defaultFromField = fromPGSFromField
53
54 instance DefaultFromField SqlFloat8 (Maybe Double) where
55 defaultFromField = fromPGSFromField
56
57 instance DefaultFromField SqlInt4 (Maybe Int) where
58 defaultFromField = fromPGSFromField
59