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
19 data NodeNodePoly node1_id node2_id score
20 = NodeNode { nodeNode_node1_id :: node1_id
21 , nodeNode_node2_id :: node2_id
22 , nodeNode_score :: score
25 type NodeNodeWrite = NodeNodePoly (Column (Nullable PGInt4)) (Column (PGInt4)) (Column (Nullable PGFloat8))
26 type NodeNodeRead = NodeNodePoly (Column (Nullable PGInt4)) (Column (PGInt4)) (Column (Nullable PGFloat8))
29 type NodeNodeReadNull = NodeNodePoly (Column (Nullable PGInt4)) (Column (Nullable PGInt4)) (Column (Nullable PGFloat8))
32 -- type NodeNodeNodeJoined = (Co
37 type NodeNode = NodeNodePoly Int Int (Maybe Double)
39 $(makeAdaptorAndInstance "pNodeNode" ''NodeNodePoly)
40 $(makeLensesWith abbreviatedFields ''NodeNodePoly)
43 nodeNodeTable :: Table NodeNodeWrite NodeNodeRead
44 nodeNodeTable = Table "nodes_nodes" (pNodeNode NodeNode { nodeNode_node1_id = required "node1_id"
45 , nodeNode_node2_id = required "node2_id"
46 , nodeNode_score = required "score"
51 queryNodeNodeTable :: Query NodeNodeRead
52 queryNodeNodeTable = queryTable nodeNodeTable
55 -- | not optimized (get all ngrams without filters)
56 nodeNodes :: PGS.Connection -> IO [NodeNode]
57 nodeNodes conn = runQuery conn queryNodeNodeTable
59 instance QueryRunnerColumnDefault (Nullable PGInt4) Int where
60 queryRunnerColumnDefault = fieldQueryRunnerColumn
62 instance QueryRunnerColumnDefault PGFloat8 (Maybe Double) where
63 queryRunnerColumnDefault = fieldQueryRunnerColumn