NodeNode.hs 2.83 KB
Newer Older
1
{-|
2
Module      : Gargantext.Database.Schema.NodeNode
3 4 5 6 7 8 9 10 11 12 13
Description : 
Copyright   : (c) CNRS, 2017-Present
License     : AGPL + CECILL v3
Maintainer  : team@gargantext.org
Stability   : experimental
Portability : POSIX

Here is a longer description of this module, containing some
commentary with @some markup@.
-}

14 15
{-# OPTIONS_GHC -fno-warn-orphans #-}

16 17
{-# LANGUAGE Arrows                 #-}
{-# LANGUAGE FunctionalDependencies #-}
18
{-# LANGUAGE QuasiQuotes            #-}
19 20
{-# LANGUAGE TemplateHaskell        #-}

21
module Gargantext.Database.Schema.NodeNode where
22

23
import Gargantext.Core.Types
24
import Gargantext.Database.Schema.Prelude
25
import Gargantext.Prelude
26

27

28 29
data NodeNodePoly node1_id node2_id score cat
                   = NodeNode { _nn_node1_id   :: !node1_id
30 31 32
                              , _nn_node2_id   :: !node2_id
                              , _nn_score      :: !score
                              , _nn_category   :: !cat
33 34
                              } deriving (Show)

35
type NodeNodeWrite     = NodeNodePoly (Column (PGInt4))
36 37
                                      (Column (PGInt4))
                                      (Maybe  (Column (PGFloat8)))
38
                                      (Maybe  (Column (PGInt4)))
39 40 41 42

type NodeNodeRead      = NodeNodePoly (Column (PGInt4))
                                      (Column (PGInt4))
                                      (Column (PGFloat8))
43
                                      (Column (PGInt4))
44

45 46
type NodeNodeReadNull  = NodeNodePoly (Column (Nullable PGInt4))
                                      (Column (Nullable PGInt4))
Alexandre Delanoë's avatar
Alexandre Delanoë committed
47
                                      (Column (Nullable PGFloat8))
48
                                      (Column (Nullable PGInt4))
49

50
type NodeNode = NodeNodePoly NodeId NodeId (Maybe Double) (Maybe Int)
51 52

$(makeAdaptorAndInstance "pNodeNode" ''NodeNodePoly)
53
makeLenses ''NodeNodePoly
54

55
nodeNodeTable :: Table NodeNodeWrite NodeNodeRead
56 57 58 59 60 61 62 63 64
nodeNodeTable  =
  Table "nodes_nodes"
         ( pNodeNode
           NodeNode { _nn_node1_id = required "node1_id"
                    , _nn_node2_id = required "node2_id"
                    , _nn_score    = optional "score"
                    , _nn_category = optional "category"
                    }
                )
65

66
instance QueryRunnerColumnDefault (Nullable PGInt4)   Int            where
67 68
    queryRunnerColumnDefault = fieldQueryRunnerColumn

69
instance QueryRunnerColumnDefault (Nullable PGFloat8) Int            where
70 71
    queryRunnerColumnDefault = fieldQueryRunnerColumn

72
instance QueryRunnerColumnDefault (Nullable PGFloat8) Double         where
73 74
    queryRunnerColumnDefault = fieldQueryRunnerColumn

75
instance QueryRunnerColumnDefault PGFloat8            (Maybe Double) where
76
    queryRunnerColumnDefault = fieldQueryRunnerColumn
77

78
instance QueryRunnerColumnDefault PGInt4              (Maybe Int)    where
79 80
    queryRunnerColumnDefault = fieldQueryRunnerColumn