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