2 Module : Gargantext.Database.Schema.NodeNodeNgram
3 Description : TODO: remove this module and table in database
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
12 {-# LANGUAGE NoImplicitPrelude #-}
13 {-# LANGUAGE TemplateHaskell #-}
14 {-# LANGUAGE FlexibleInstances #-}
15 {-# LANGUAGE MultiParamTypeClasses #-}
16 {-# LANGUAGE FunctionalDependencies #-}
17 {-# LANGUAGE Arrows #-}
18 {-# OPTIONS_GHC -fno-warn-orphans #-}
21 module Gargantext.Database.Schema.NodeNodeNgram where
24 import Data.Maybe (Maybe)
25 import Data.Profunctor.Product.TH (makeAdaptorAndInstance)
26 import Control.Lens.TH (makeLensesWith, abbreviatedFields)
27 import qualified Database.PostgreSQL.Simple as PGS
32 data NodeNodeNgramPoly node1_id node2_id ngram_id score
33 = NodeNodeNgram { nodeNodeNgram_node1_id :: node1_id
34 , nodeNodeNgram_node2_id :: node2_id
35 , nodeNodeNgram_ngram_id :: ngram_id
36 , nodeNodeNgram_score :: score
40 type NodeNodeNgramWrite = NodeNodeNgramPoly (Column PGInt4 )
43 (Maybe (Column PGFloat8))
45 type NodeNodeNgramRead = NodeNodeNgramPoly (Column PGInt4 )
50 type NodeNodeNgramReadNull = NodeNodeNgramPoly (Column (Nullable PGInt4 ))
51 (Column (Nullable PGInt4 ))
52 (Column (Nullable PGInt4 ))
53 (Column (Nullable PGFloat8))
55 type NodeNodeNgram = NodeNodeNgramPoly Int
61 $(makeAdaptorAndInstance "pNodeNodeNgram" ''NodeNodeNgramPoly)
62 $(makeLensesWith abbreviatedFields ''NodeNodeNgramPoly)
64 nodeNodeNgramTable :: Table NodeNodeNgramWrite NodeNodeNgramRead
65 nodeNodeNgramTable = Table "nodes_nodes_ngrams"
66 ( pNodeNodeNgram NodeNodeNgram
67 { nodeNodeNgram_node1_id = required "node1_id"
68 , nodeNodeNgram_node2_id = required "node2_id"
69 , nodeNodeNgram_ngram_id = required "ngram_id"
70 , nodeNodeNgram_score = optional "score"
75 queryNodeNodeNgramTable :: Query NodeNodeNgramRead
76 queryNodeNodeNgramTable = queryTable nodeNodeNgramTable
78 -- | not optimized (get all ngrams without filters)
79 nodeNodeNgrams :: PGS.Connection -> IO [NodeNodeNgram]
80 nodeNodeNgrams conn = runQuery conn queryNodeNodeNgramTable
82 instance QueryRunnerColumnDefault PGFloat8 (Maybe Double) where
83 queryRunnerColumnDefault = fieldQueryRunnerColumn