2 Module : Gargantext.Database.NodeNode
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
10 Here is a longer description of this module, containing some
11 commentary with @some markup@.
14 {-# OPTIONS_GHC -fno-warn-orphans #-}
16 {-# LANGUAGE Arrows #-}
17 {-# LANGUAGE FlexibleInstances #-}
18 {-# LANGUAGE FunctionalDependencies #-}
19 {-# LANGUAGE MultiParamTypeClasses #-}
20 {-# LANGUAGE NoImplicitPrelude #-}
21 {-# LANGUAGE TemplateHaskell #-}
23 module Gargantext.Database.NodeNode where
25 import Gargantext.Database.Node (Cmd(..), mkCmd)
26 import Gargantext.Prelude
27 import Data.Maybe (Maybe)
28 import Data.Profunctor.Product.TH (makeAdaptorAndInstance)
29 import Control.Lens.TH (makeLensesWith, abbreviatedFields)
34 data NodeNodePoly node1_id node2_id score fav del
35 = NodeNode { nodeNode_node1_id :: node1_id
36 , nodeNode_node2_id :: node2_id
37 , nodeNode_score :: score
38 , nodeNode_favorite :: fav
39 , nodeNode_delete :: del
42 type NodeNodeWrite = NodeNodePoly (Column (PGInt4))
44 (Maybe (Column (PGFloat8)))
45 (Maybe (Column (PGBool)))
46 (Maybe (Column (PGBool)))
48 type NodeNodeRead = NodeNodePoly (Column (PGInt4))
54 type NodeNodeReadNull = NodeNodePoly (Column (Nullable PGInt4))
55 (Column (Nullable PGInt4))
56 (Column (Nullable PGFloat8))
57 (Column (Nullable PGBool))
58 (Column (Nullable PGBool))
60 type NodeNode = NodeNodePoly Int Int (Maybe Double) (Maybe Bool) (Maybe Bool)
62 $(makeAdaptorAndInstance "pNodeNode" ''NodeNodePoly)
63 $(makeLensesWith abbreviatedFields ''NodeNodePoly)
65 nodeNodeTable :: Table NodeNodeWrite NodeNodeRead
66 nodeNodeTable = Table "nodes_nodes" (pNodeNode
67 NodeNode { nodeNode_node1_id = required "node1_id"
68 , nodeNode_node2_id = required "node2_id"
69 , nodeNode_score = optional "score"
70 , nodeNode_favorite = optional "favorite"
71 , nodeNode_delete = optional "delete"
75 queryNodeNodeTable :: Query NodeNodeRead
76 queryNodeNodeTable = queryTable nodeNodeTable
79 -- | not optimized (get all ngrams without filters)
80 nodesNodes :: Cmd [NodeNode]
81 nodesNodes = mkCmd $ \c -> runQuery c queryNodeNodeTable
83 instance QueryRunnerColumnDefault (Nullable PGInt4) Int where
84 queryRunnerColumnDefault = fieldQueryRunnerColumn
86 instance QueryRunnerColumnDefault PGFloat8 (Maybe Double) where
87 queryRunnerColumnDefault = fieldQueryRunnerColumn
89 instance QueryRunnerColumnDefault PGBool (Maybe Bool) where
90 queryRunnerColumnDefault = fieldQueryRunnerColumn