]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Schema/NodeNode.hs
[Community] Type Design (WIP)
[gargantext.git] / src / Gargantext / Database / Schema / NodeNode.hs
1 {-|
2 Module : Gargantext.Database.Schema.NodeNode
3 Description :
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10 Here is a longer description of this module, containing some
11 commentary with @some markup@.
12 -}
13
14 {-# OPTIONS_GHC -fno-warn-orphans #-}
15
16 {-# LANGUAGE Arrows #-}
17 {-# LANGUAGE FunctionalDependencies #-}
18 {-# LANGUAGE QuasiQuotes #-}
19 {-# LANGUAGE TemplateHaskell #-}
20
21 module Gargantext.Database.Schema.NodeNode where
22
23 import Data.Maybe (Maybe)
24 import Gargantext.Core.Types
25 import Gargantext.Database.Schema.Prelude
26 import Gargantext.Prelude
27
28
29 data NodeNodePoly n node1_id node2_id score cat
30 = NodeNode { _nn_id :: !n
31 , _nn_node1_id :: !node1_id
32 , _nn_node2_id :: !node2_id
33 , _nn_score :: !score
34 , _nn_category :: !cat
35 } deriving (Show)
36
37 type NodeNodeWrite = NodeNodePoly (Maybe (Column (PGInt4)))
38 (Column (PGInt4))
39 (Column (PGInt4))
40 (Maybe (Column (PGFloat8)))
41 (Maybe (Column (PGInt4)))
42
43 type NodeNodeRead = NodeNodePoly (Column (PGInt4))
44 (Column (PGInt4))
45 (Column (PGInt4))
46 (Column (PGFloat8))
47 (Column (PGInt4))
48
49 type NodeNodeReadNull = NodeNodePoly (Column (Nullable PGInt4))
50 (Column (Nullable PGInt4))
51 (Column (Nullable PGInt4))
52 (Column (Nullable PGFloat8))
53 (Column (Nullable PGInt4))
54
55 type NodeNode = NodeNodePoly (Maybe Int) NodeId NodeId (Maybe Double) (Maybe Int)
56
57 $(makeAdaptorAndInstance "pNodeNode" ''NodeNodePoly)
58 makeLenses ''NodeNodePoly
59
60 nodeNodeTable :: Table NodeNodeWrite NodeNodeRead
61 nodeNodeTable = Table "nodes_nodes" (pNodeNode
62 NodeNode { _nn_id = optional "id"
63 , _nn_node1_id = required "node1_id"
64 , _nn_node2_id = required "node2_id"
65 , _nn_score = optional "score"
66 , _nn_category = optional "category"
67 }
68 )
69
70
71
72 instance QueryRunnerColumnDefault (Nullable PGInt4) Int where
73 queryRunnerColumnDefault = fieldQueryRunnerColumn
74
75 instance QueryRunnerColumnDefault (Nullable PGFloat8) Int where
76 queryRunnerColumnDefault = fieldQueryRunnerColumn
77
78 instance QueryRunnerColumnDefault (Nullable PGFloat8) Double where
79 queryRunnerColumnDefault = fieldQueryRunnerColumn
80
81 instance QueryRunnerColumnDefault PGFloat8 (Maybe Double) where
82 queryRunnerColumnDefault = fieldQueryRunnerColumn
83
84 instance QueryRunnerColumnDefault PGInt4 (Maybe Int) where
85 queryRunnerColumnDefault = fieldQueryRunnerColumn
86