1 {-# LANGUAGE TemplateHaskell #-}
2 {-# LANGUAGE FlexibleInstances #-}
3 {-# LANGUAGE MultiParamTypeClasses #-}
4 {-# LANGUAGE FunctionalDependencies #-}
5 {-# LANGUAGE Arrows #-}
6 {-# OPTIONS_GHC -fno-warn-orphans #-}
8 module Gargantext.Database.NodeNode where
11 import Data.Maybe (Maybe)
12 import Data.Profunctor.Product.TH (makeAdaptorAndInstance)
13 import Control.Lens.TH (makeLensesWith, abbreviatedFields)
14 import qualified Database.PostgreSQL.Simple as PGS
18 import Gargantext.Database.Private (infoGargandb)
20 data NodeNodePoly node1_id node2_id score
21 = NodeNode { nodeNode_node1_id :: node1_id
22 , nodeNode_node2_id :: node2_id
23 , nodeNode_score :: score
26 type NodeNodeWrite = NodeNodePoly (Column PGInt4) (Column PGInt4) (Maybe (Column PGFloat8))
27 type NodeNodeRead = NodeNodePoly (Column PGInt4) (Column PGInt4) (Column PGFloat8)
30 type NodeNode = NodeNodePoly Int Int (Maybe Double)
32 $(makeAdaptorAndInstance "pNodeNode" ''NodeNodePoly)
33 $(makeLensesWith abbreviatedFields ''NodeNodePoly)
36 nodeNodeTable :: Table NodeNodeWrite NodeNodeRead
37 nodeNodeTable = Table "nodes_nodes" (pNodeNode NodeNode { nodeNode_node1_id = required "node1_id"
38 , nodeNode_node2_id = required "node2_id"
39 , nodeNode_score = optional "score"
44 queryNodeNodeTable :: Query NodeNodeRead
45 queryNodeNodeTable = queryTable nodeNodeTable
48 -- | not optimized (get all ngrams without filters)
49 nodeNodes :: IO [NodeNode]
51 conn <- PGS.connect infoGargandb
52 runQuery conn queryNodeNodeTable
54 instance QueryRunnerColumnDefault PGFloat8 (Maybe Double) where
55 queryRunnerColumnDefault = fieldQueryRunnerColumn