]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Schema/NodeNode.hs
[FIX] more strict data
[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 Gargantext.Core.Types
24 import Gargantext.Database.Schema.Prelude
25 import Gargantext.Prelude
26
27
28 data NodeNodePoly node1_id node2_id score cat
29 = NodeNode { _nn_node1_id :: !node1_id
30 , _nn_node2_id :: !node2_id
31 , _nn_score :: !score
32 , _nn_category :: !cat
33 } deriving (Show)
34
35 type NodeNodeWrite = NodeNodePoly (Column (PGInt4))
36 (Column (PGInt4))
37 (Maybe (Column (PGFloat8)))
38 (Maybe (Column (PGInt4)))
39
40 type NodeNodeRead = NodeNodePoly (Column (PGInt4))
41 (Column (PGInt4))
42 (Column (PGFloat8))
43 (Column (PGInt4))
44
45 type NodeNodeReadNull = NodeNodePoly (Column (Nullable PGInt4))
46 (Column (Nullable PGInt4))
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 nodeNodeTable =
57 Table "nodes_nodes"
58 ( pNodeNode
59 NodeNode { _nn_node1_id = required "node1_id"
60 , _nn_node2_id = required "node2_id"
61 , _nn_score = optional "score"
62 , _nn_category = optional "category"
63 }
64 )
65
66 instance QueryRunnerColumnDefault (Nullable PGInt4) Int where
67 queryRunnerColumnDefault = fieldQueryRunnerColumn
68
69 instance QueryRunnerColumnDefault (Nullable PGFloat8) Int where
70 queryRunnerColumnDefault = fieldQueryRunnerColumn
71
72 instance QueryRunnerColumnDefault (Nullable PGFloat8) Double where
73 queryRunnerColumnDefault = fieldQueryRunnerColumn
74
75 instance QueryRunnerColumnDefault PGFloat8 (Maybe Double) where
76 queryRunnerColumnDefault = fieldQueryRunnerColumn
77
78 instance QueryRunnerColumnDefault PGInt4 (Maybe Int) where
79 queryRunnerColumnDefault = fieldQueryRunnerColumn
80