1 {-# LANGUAGE TemplateHaskell #-}
2 {-# LANGUAGE FlexibleInstances #-}
3 {-# LANGUAGE MultiParamTypeClasses #-}
4 {-# LANGUAGE FunctionalDependencies #-}
5 {-# LANGUAGE Arrows #-}
7 module Data.Gargantext.Database.NodeNode where
10 import Data.Time (UTCTime)
11 import Data.Text (Text)
12 import Data.Maybe (Maybe)
13 import Data.Profunctor.Product.TH (makeAdaptorAndInstance)
14 import Control.Lens.TH (makeLensesWith, abbreviatedFields)
15 import Control.Arrow (returnA)
16 import qualified Database.PostgreSQL.Simple as PGS
18 import qualified Opaleye as O
19 import Opaleye (Column, PGBool, PGInt4, PGText, PGTimestamptz, PGFloat8
21 , QueryRunnerColumnDefault, queryRunnerColumnDefault
22 , fieldQueryRunnerColumn
27 import Data.Gargantext.Database.Private (infoGargandb)
28 import Data.Gargantext.Database.Instances
30 data NodeNodePoly node1_id node2_id score
31 = NodeNode { nodeNode_node1_id :: node1_id
32 , nodeNode_node2_id :: node2_id
33 , nodeNode_score :: score
36 type NodeNodeWrite = NodeNodePoly (Column PGInt4) (Column PGInt4) (Maybe (Column PGFloat8))
37 type NodeNodeRead = NodeNodePoly (Column PGInt4) (Column PGInt4) (Column PGFloat8)
40 type NodeNode = NodeNodePoly Int Int (Maybe Double)
42 $(makeAdaptorAndInstance "pNodeNode" ''NodeNodePoly)
43 $(makeLensesWith abbreviatedFields ''NodeNodePoly)
46 nodeNodeTable :: O.Table NodeNodeWrite NodeNodeRead
47 nodeNodeTable = O.Table "nodes_nodes" (pNodeNode NodeNode { nodeNode_node1_id = required "node1_id"
48 , nodeNode_node2_id = required "node2_id"
49 , nodeNode_score = optional "score"
54 queryNodeNodeTable :: Query NodeNodeRead
55 queryNodeNodeTable = O.queryTable nodeNodeTable
58 -- | not optimized (get all ngrams without filters)
59 nodeNodes :: IO [NodeNode]
61 conn <- PGS.connect infoGargandb
62 O.runQuery conn queryNodeNodeTable