Types.hs 1.07 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
{-|
Module      : Gargantext.Database.Types
Description : Specific Types to manage core Gargantext type with database
Copyright   : (c) CNRS, 2017-Present
License     : AGPL + CECILL v3
Maintainer  : team@gargantext.org
Stability   : experimental
Portability : POSIX

-}

{-# LANGUAGE TemplateHaskell        #-}

module Gargantext.Database.Types
  where

17
import Data.Hashable (Hashable)
18
import Gargantext.Core.Text (HasText(..))
19
import Gargantext.Database.Schema.Prelude
20
import Gargantext.Prelude
21 22 23 24
import qualified Database.PostgreSQL.Simple as PGS


-- | Index memory of any type in Gargantext
25
data Indexed i a =
26 27
  Indexed { _index     :: !i
          , _unIndex   :: !a
28 29 30 31 32
          }
  deriving (Show, Generic, Eq, Ord)

makeLenses ''Indexed

33 34
----------------------------------------------------------------------
-- | Main instances
35
instance (FromField i, FromField a) => PGS.FromRow (Indexed i a) where
36 37
  fromRow = Indexed <$> field <*> field

38 39 40 41
instance HasText a => HasText (Indexed i a)
  where
    hasText (Indexed _ a) = hasText a

42
instance (Hashable a, Hashable b) => Hashable (Indexed a b)