1 {-# LANGUAGE TemplateHaskell #-}
2 {-# LANGUAGE FlexibleInstances #-}
3 {-# LANGUAGE MultiParamTypeClasses #-}
4 {-# LANGUAGE FunctionalDependencies #-}
5 {-# LANGUAGE Arrows #-}
7 module Data.Gargantext.Database.NodeNodeNgram 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
26 import Data.Gargantext.Database.Private (infoGargandb)
27 import Data.Gargantext.Database.Instances
29 data NodeNodeNgramPoly node1_id node2_id ngram_id score
30 = NodeNodeNgram { nodeNodeNgram_node1_id :: node1_id
31 , nodeNodeNgram_node2_id :: node2_id
32 , nodeNodeNgram_ngram_id :: ngram_id
33 , nodeNodeNgram_score :: score
37 type NodeNodeNgramWrite = NodeNodeNgramPoly (Column PGInt4) (Column PGInt4) (Column PGInt4) (Maybe (Column PGFloat8))
38 type NodeNodeNgramRead = NodeNodeNgramPoly (Column PGInt4) (Column PGInt4) (Column PGInt4) (Column PGFloat8)
41 type NodeNodeNgram = NodeNodeNgramPoly Int Int Int (Maybe Double)
43 $(makeAdaptorAndInstance "pNodeNodeNgram" ''NodeNodeNgramPoly)
44 $(makeLensesWith abbreviatedFields ''NodeNodeNgramPoly)
47 nodeNodeNgramTable :: O.Table NodeNodeNgramWrite NodeNodeNgramRead
48 nodeNodeNgramTable = O.Table "nodes_nodes_ngrams" ( pNodeNodeNgram NodeNodeNgram
49 { nodeNodeNgram_node1_id = O.required "node1_id"
50 , nodeNodeNgram_node2_id = O.required "node2_id"
51 , nodeNodeNgram_ngram_id = O.required "ngram_id"
52 , nodeNodeNgram_score = O.optional "score"
57 queryNodeNodeNgramTable :: Query NodeNodeNgramRead
58 queryNodeNodeNgramTable = O.queryTable nodeNodeNgramTable
61 -- | not optimized (get all ngrams without filters)
62 nodeNodeNgrams :: IO [NodeNodeNgram]
64 conn <- PGS.connect infoGargandb
65 O.runQuery conn queryNodeNodeNgramTable