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 data NodeNgramNgramPoly node_id ngram1_id ngram2_id weight
19 = NodeNgramNgram { nodeNgramNgram_NodeNgramNgram_NodeId :: node_id
20 , nodeNgramNgram_NodeNgramNgram_Ngram1Id :: ngram1_id
21 , nodeNgramNgram_NodeNgramNgram_Ngram2Id :: ngram2_id
22 , nodeNgramNgram_NodeNgramNgram_Weight :: weight
26 type NodeNgramNgramWrite = NodeNgramNgramPoly (Maybe (Column PGInt4 ))
29 (Maybe (Column PGFloat8))
31 type NodeNgramNgramRead = NodeNgramNgramPoly (Column PGInt4 )
36 type NodeNgramNgram = NodeNgramNgramPoly (Maybe Int )
41 $(makeAdaptorAndInstance "pNodeNgramNgram" ''NodeNgramNgramPoly)
42 $(makeLensesWith abbreviatedFields ''NodeNgramNgramPoly)
45 nodeNgramNgramTable :: Table NodeNgramNgramWrite NodeNgramNgramRead
46 nodeNgramNgramTable = Table "nodes_ngrams_ngrams"
47 ( pNodeNgramNgram NodeNgramNgram
48 { nodeNgramNgram_NodeNgramNgram_NodeId = optional "node_id"
49 , nodeNgramNgram_NodeNgramNgram_Ngram1Id = required "ngram1_id"
50 , nodeNgramNgram_NodeNgramNgram_Ngram2Id = required "ngram2_id"
51 , nodeNgramNgram_NodeNgramNgram_Weight = optional "weight"
55 queryNodeNgramNgramTable :: Query NodeNgramNgramRead
56 queryNodeNgramNgramTable = queryTable nodeNgramNgramTable
58 -- | not optimized (get all ngrams without filters)
59 nodeNgramNgrams :: PGS.Connection -> IO [NodeNgramNgram]
60 nodeNgramNgrams conn = runQuery conn queryNodeNgramNgramTable
62 instance QueryRunnerColumnDefault PGInt4 (Maybe Int) where
63 queryRunnerColumnDefault = fieldQueryRunnerColumn
65 instance QueryRunnerColumnDefault PGFloat8 (Maybe Double) where
66 queryRunnerColumnDefault = fieldQueryRunnerColumn