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.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
25 -- | Index memory of any type in Gargantext
27 Indexed { _index :: !i
30 deriving (Show, Generic, Eq, Ord)
34 ----------------------------------------------------------------------
36 instance (FromField i, FromField a) => PGS.FromRow (Indexed i a) where
37 fromRow = Indexed <$> field <*> field
39 instance HasText a => HasText (Indexed i a)
41 hasText (Indexed _ a) = hasText a
43 instance (Hashable a, Hashable b) => Hashable (Indexed a b)
45 instance DefaultFromField (Nullable SqlInt4) Int where
46 defaultFromField = fromPGSFromField
48 instance DefaultFromField (Nullable SqlFloat8) Int where
49 defaultFromField = fromPGSFromField
51 instance DefaultFromField (Nullable SqlFloat8) Double where
52 defaultFromField = fromPGSFromField
54 instance DefaultFromField SqlFloat8 (Maybe Double) where
55 defaultFromField = fromPGSFromField
57 instance DefaultFromField SqlInt4 (Maybe Int) where
58 defaultFromField = fromPGSFromField