]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Schema/NodeNode.hs
[FIX] Ngrams in list
[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 (SqlInt4))
36 (Column (SqlInt4))
37 (Maybe (Column (SqlFloat8)))
38 (Maybe (Column (SqlInt4)))
39
40 type NodeNodeRead = NodeNodePoly (Column (SqlInt4))
41 (Column (SqlInt4))
42 (Column (SqlFloat8))
43 (Column (SqlInt4))
44
45 type NodeNodeReadNull = NodeNodePoly (Column (Nullable SqlInt4))
46 (Column (Nullable SqlInt4))
47 (Column (Nullable SqlFloat8))
48 (Column (Nullable SqlInt4))
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 = requiredTableField "node1_id"
60 , _nn_node2_id = requiredTableField "node2_id"
61 , _nn_score = optionalTableField "score"
62 , _nn_category = optionalTableField "category"
63 }
64 )
65
66 instance DefaultFromField (Nullable SqlInt4) Int where
67 defaultFromField = fromPGSFromField
68
69 instance DefaultFromField (Nullable SqlFloat8) Int where
70 defaultFromField = fromPGSFromField
71
72 instance DefaultFromField (Nullable SqlFloat8) Double where
73 defaultFromField = fromPGSFromField
74
75 instance DefaultFromField SqlFloat8 (Maybe Double) where
76 defaultFromField = fromPGSFromField
77
78 instance DefaultFromField SqlInt4 (Maybe Int) where
79 defaultFromField = fromPGSFromField
80