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
12 {-# OPTIONS_GHC -fno-warn-orphans #-}
13 {-# LANGUAGE TemplateHaskell #-}
15 module Gargantext.Database.Types
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
26 -- | Index memory of any type in Gargantext
28 Indexed { _index :: !i
31 deriving (Show, Generic, Eq, Ord)
35 ----------------------------------------------------------------------
37 instance (FromField i, FromField a) => PGS.FromRow (Indexed i a) where
38 fromRow = Indexed <$> field <*> field
40 instance HasText a => HasText (Indexed i a)
42 hasText (Indexed _ a) = hasText a
44 instance (Hashable a, Hashable b) => Hashable (Indexed a b)
46 instance DefaultFromField (Nullable SqlInt4) Int where
47 defaultFromField = fromPGSFromField
49 instance DefaultFromField (Nullable SqlFloat8) Int where
50 defaultFromField = fromPGSFromField
52 instance DefaultFromField (Nullable SqlFloat8) Double where
53 defaultFromField = fromPGSFromField
55 instance DefaultFromField SqlFloat8 (Maybe Double) where
56 defaultFromField = fromPGSFromField
58 instance DefaultFromField SqlInt4 (Maybe Int) where
59 defaultFromField = fromPGSFromField
61 instance DefaultFromField (Nullable SqlText) Text where
62 defaultFromField = fromPGSFromField