1 {-# LANGUAGE TemplateHaskell #-}
2 {-# LANGUAGE FlexibleInstances #-}
3 {-# LANGUAGE MultiParamTypeClasses #-}
4 {-# LANGUAGE FunctionalDependencies #-}
5 {-# LANGUAGE Arrows #-}
6 {-# OPTIONS_GHC -fno-warn-orphans #-}
9 module Data.Gargantext.Database.NodeNgram where
12 import Data.Maybe (Maybe)
13 import Data.Profunctor.Product.TH (makeAdaptorAndInstance)
14 import Control.Lens.TH (makeLensesWith, abbreviatedFields)
15 import qualified Database.PostgreSQL.Simple as PGS
19 import Data.Gargantext.Database.Private (infoGargandb)
21 data NodeNgramPoly id node_id ngram_id weight
22 = NodeNgram { nodeNgram_NodeNgramId :: id
23 , nodeNgram_NodeNgramNodeId :: node_id
24 , nodeNgram_NodeNgramNgramId :: ngram_id
25 , nodeNgram_NodeNgramWeight :: weight
28 type NodeNgramWrite = NodeNgramPoly (Maybe (Column PGInt4)) (Column PGInt4) (Column PGInt4) (Maybe (Column PGFloat8))
29 type NodeNgramRead = NodeNgramPoly (Column PGInt4) (Column PGInt4) (Column PGInt4) ((Column PGFloat8))
32 type NodeNgram = NodeNgramPoly (Maybe Int) Int Int (Maybe Double)
34 $(makeAdaptorAndInstance "pNodeNgram" ''NodeNgramPoly)
35 $(makeLensesWith abbreviatedFields ''NodeNgramPoly)
38 nodeNgramTable :: Table NodeNgramWrite NodeNgramRead
39 nodeNgramTable = Table "nodes_ngrams" (pNodeNgram NodeNgram { nodeNgram_NodeNgramId = optional "id"
40 , nodeNgram_NodeNgramNodeId = required "node_id"
41 , nodeNgram_NodeNgramNgramId = required "ngram_id"
42 , nodeNgram_NodeNgramWeight = optional "weight"
47 queryNodeNgramTable :: Query NodeNgramRead
48 queryNodeNgramTable = queryTable nodeNgramTable
51 instance QueryRunnerColumnDefault PGInt4 (Maybe Int) where
52 queryRunnerColumnDefault = fieldQueryRunnerColumn
54 instance QueryRunnerColumnDefault PGFloat8 (Maybe Double) where
55 queryRunnerColumnDefault = fieldQueryRunnerColumn
58 -- | not optimized (get all ngrams without filters)
59 nodeNgrams :: IO [NodeNgram]
61 conn <- PGS.connect infoGargandb
62 runQuery conn queryNodeNgramTable