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.NodeNgramNgram 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 NodeNgramNgramPoly node_id ngram1_id ngram2_id weight
21 = NodeNgramNgram { nodeNgramNgram_NodeNgramNgram_NodeId :: node_id
22 , nodeNgramNgram_NodeNgramNgram_Ngram1Id :: ngram1_id
23 , nodeNgramNgram_NodeNgramNgram_Ngram2Id :: ngram2_id
24 , nodeNgramNgram_NodeNgramNgram_Weight :: weight
28 type NodeNgramNgramWrite = NodeNgramNgramPoly (Maybe (Column PGInt4)) (Column PGInt4) (Column PGInt4) (Maybe (Column PGFloat8))
29 type NodeNgramNgramRead = NodeNgramNgramPoly (Column PGInt4) (Column PGInt4) (Column PGInt4) (Column PGFloat8)
32 type NodeNgramNgram = NodeNgramNgramPoly (Maybe Int) Int Int (Maybe Double)
34 $(makeAdaptorAndInstance "pNodeNgramNgram" ''NodeNgramNgramPoly)
35 $(makeLensesWith abbreviatedFields ''NodeNgramNgramPoly)
38 nodeNgramNgramTable :: Table NodeNgramNgramWrite NodeNgramNgramRead
39 nodeNgramNgramTable = Table "nodes_ngrams_ngrams" ( pNodeNgramNgram NodeNgramNgram
40 { nodeNgramNgram_NodeNgramNgram_NodeId = optional "node_id"
41 , nodeNgramNgram_NodeNgramNgram_Ngram1Id = required "ngram1_id"
42 , nodeNgramNgram_NodeNgramNgram_Ngram2Id = required "ngram2_id"
43 , nodeNgramNgram_NodeNgramNgram_Weight = optional "weight"
48 queryNodeNgramNgramTable :: Query NodeNgramNgramRead
49 queryNodeNgramNgramTable = queryTable nodeNgramNgramTable
52 -- | not optimized (get all ngrams without filters)
53 nodeNgramNgrams :: IO [NodeNgramNgram]
55 conn <- PGS.connect infoGargandb
56 runQuery conn queryNodeNgramNgramTable
58 instance QueryRunnerColumnDefault PGInt4 (Maybe Int) where
59 queryRunnerColumnDefault = fieldQueryRunnerColumn
61 instance QueryRunnerColumnDefault PGFloat8 (Maybe Double) where
62 queryRunnerColumnDefault = fieldQueryRunnerColumn