]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/NodeNodeNgram.hs
Need to derive Arbitrary for ParseError and Eq for ZonedTime
[gargantext.git] / src / Gargantext / Database / NodeNodeNgram.hs
1 {-# LANGUAGE TemplateHaskell #-}
2 {-# LANGUAGE FlexibleInstances #-}
3 {-# LANGUAGE MultiParamTypeClasses #-}
4 {-# LANGUAGE FunctionalDependencies #-}
5 {-# LANGUAGE Arrows #-}
6 {-# OPTIONS_GHC -fno-warn-orphans #-}
7
8
9 module Gargantext.Database.NodeNodeNgram where
10
11 import Prelude
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
16
17 import Opaleye
18
19
20 data NodeNodeNgramPoly node1_id node2_id ngram_id score
21 = NodeNodeNgram { nodeNodeNgram_node1_id :: node1_id
22 , nodeNodeNgram_node2_id :: node2_id
23 , nodeNodeNgram_ngram_id :: ngram_id
24 , nodeNodeNgram_score :: score
25 } deriving (Show)
26
27
28 type NodeNodeNgramWrite = NodeNodeNgramPoly (Column PGInt4) (Column PGInt4) (Column PGInt4) (Maybe (Column PGFloat8))
29 type NodeNodeNgramRead = NodeNodeNgramPoly (Column PGInt4) (Column PGInt4) (Column PGInt4) (Column PGFloat8)
30
31
32 type NodeNodeNgram = NodeNodeNgramPoly Int Int Int (Maybe Double)
33
34 $(makeAdaptorAndInstance "pNodeNodeNgram" ''NodeNodeNgramPoly)
35 $(makeLensesWith abbreviatedFields ''NodeNodeNgramPoly)
36
37
38 nodeNodeNgramTable :: Table NodeNodeNgramWrite NodeNodeNgramRead
39 nodeNodeNgramTable = Table "nodes_nodes_ngrams" ( pNodeNodeNgram NodeNodeNgram
40 { nodeNodeNgram_node1_id = required "node1_id"
41 , nodeNodeNgram_node2_id = required "node2_id"
42 , nodeNodeNgram_ngram_id = required "ngram_id"
43 , nodeNodeNgram_score = optional "score"
44 }
45 )
46
47
48 queryNodeNodeNgramTable :: Query NodeNodeNgramRead
49 queryNodeNodeNgramTable = queryTable nodeNodeNgramTable
50
51
52 -- | not optimized (get all ngrams without filters)
53 nodeNodeNgrams :: PGS.Connection -> IO [NodeNodeNgram]
54 nodeNodeNgrams conn = runQuery conn queryNodeNodeNgramTable
55
56
57 instance QueryRunnerColumnDefault PGFloat8 (Maybe Double) where
58 queryRunnerColumnDefault = fieldQueryRunnerColumn