]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Schema/NodeNode.hs
Merge branch 'dev' into dev-doc-annotation-issue
[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 node1_id node2_id score cat
30 = NodeNode { _nn_node1_id :: !node1_id
31 , _nn_node2_id :: !node2_id
32 , _nn_score :: !score
33 , _nn_category :: !cat
34 } deriving (Show)
35
36 type NodeNodeWrite = NodeNodePoly (Column (PGInt4))
37 (Column (PGInt4))
38 (Maybe (Column (PGFloat8)))
39 (Maybe (Column (PGInt4)))
40
41 type NodeNodeRead = NodeNodePoly (Column (PGInt4))
42 (Column (PGInt4))
43 (Column (PGFloat8))
44 (Column (PGInt4))
45
46 type NodeNodeReadNull = NodeNodePoly (Column (Nullable PGInt4))
47 (Column (Nullable PGInt4))
48 (Column (Nullable PGFloat8))
49 (Column (Nullable PGInt4))
50
51 type NodeNode = NodeNodePoly NodeId NodeId (Maybe Double) (Maybe Int)
52
53 $(makeAdaptorAndInstance "pNodeNode" ''NodeNodePoly)
54 makeLenses ''NodeNodePoly
55
56 nodeNodeTable :: Table NodeNodeWrite NodeNodeRead
57 nodeNodeTable =
58 Table "nodes_nodes"
59 ( pNodeNode
60 NodeNode { _nn_node1_id = required "node1_id"
61 , _nn_node2_id = required "node2_id"
62 , _nn_score = optional "score"
63 , _nn_category = optional "category"
64 }
65 )
66
67 instance QueryRunnerColumnDefault (Nullable PGInt4) Int where
68 queryRunnerColumnDefault = fieldQueryRunnerColumn
69
70 instance QueryRunnerColumnDefault (Nullable PGFloat8) Int where
71 queryRunnerColumnDefault = fieldQueryRunnerColumn
72
73 instance QueryRunnerColumnDefault (Nullable PGFloat8) Double where
74 queryRunnerColumnDefault = fieldQueryRunnerColumn
75
76 instance QueryRunnerColumnDefault PGFloat8 (Maybe Double) where
77 queryRunnerColumnDefault = fieldQueryRunnerColumn
78
79 instance QueryRunnerColumnDefault PGInt4 (Maybe Int) where
80 queryRunnerColumnDefault = fieldQueryRunnerColumn
81