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
26 import Data.Maybe (Maybe)
27 import Data.Profunctor.Product.TH (makeAdaptorAndInstance)
28 import Control.Lens.TH (makeLensesWith, abbreviatedFields)
29 import qualified Database.PostgreSQL.Simple as PGS
34 data NodeNodePoly node1_id node2_id score
35 = NodeNode { nodeNode_node1_id :: node1_id
36 , nodeNode_node2_id :: node2_id
37 , nodeNode_score :: score
40 type NodeNodeWrite = NodeNodePoly (Column (Nullable PGInt4))
42 (Column (Nullable PGFloat8))
44 type NodeNodeRead = NodeNodePoly (Column (Nullable PGInt4))
46 (Column (Nullable PGFloat8))
48 type NodeNodeReadNull = NodeNodePoly (Column (Nullable PGInt4))
49 (Column (Nullable PGInt4))
50 (Column (Nullable PGFloat8))
52 type NodeNode = NodeNodePoly Int Int (Maybe Double)
54 $(makeAdaptorAndInstance "pNodeNode" ''NodeNodePoly)
55 $(makeLensesWith abbreviatedFields ''NodeNodePoly)
57 nodeNodeTable :: Table NodeNodeWrite NodeNodeRead
58 nodeNodeTable = Table "nodes_nodes" (pNodeNode NodeNode { nodeNode_node1_id = required "node1_id"
59 , nodeNode_node2_id = required "node2_id"
60 , nodeNode_score = required "score"
64 queryNodeNodeTable :: Query NodeNodeRead
65 queryNodeNodeTable = queryTable nodeNodeTable
68 -- | not optimized (get all ngrams without filters)
69 nodeNodes :: PGS.Connection -> IO [NodeNode]
70 nodeNodes conn = runQuery conn queryNodeNodeTable
72 instance QueryRunnerColumnDefault (Nullable PGInt4) Int where
73 queryRunnerColumnDefault = fieldQueryRunnerColumn
75 instance QueryRunnerColumnDefault PGFloat8 (Maybe Double) where
76 queryRunnerColumnDefault = fieldQueryRunnerColumn