]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/NodeNgramNgram.hs
[SQL/OPALEYE] leftJoin3. thanks to tomjaguarpaw https://github.com/tomjaguarpaw/haske...
[gargantext.git] / src / Gargantext / Database / NodeNgramNgram.hs
1 {-# LANGUAGE TemplateHaskell #-}
2 {-# LANGUAGE FlexibleInstances #-}
3 {-# LANGUAGE MultiParamTypeClasses #-}
4 {-# LANGUAGE FunctionalDependencies #-}
5 {-# LANGUAGE Arrows #-}
6 {-# OPTIONS_GHC -fno-warn-orphans #-}
7
8 module Gargantext.Database.NodeNgramNgram where
9
10 import Prelude
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
15
16 import Opaleye
17
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
23 } deriving (Show)
24
25
26 type NodeNgramNgramWrite = NodeNgramNgramPoly (Maybe (Column PGInt4 ))
27 (Column PGInt4 )
28 (Column PGInt4 )
29 (Maybe (Column PGFloat8))
30
31 type NodeNgramNgramRead = NodeNgramNgramPoly (Column PGInt4 )
32 (Column PGInt4 )
33 (Column PGInt4 )
34 (Column PGFloat8)
35
36 type NodeNgramNgram = NodeNgramNgramPoly (Maybe Int )
37 Int
38 Int
39 (Maybe Double)
40
41 $(makeAdaptorAndInstance "pNodeNgramNgram" ''NodeNgramNgramPoly)
42 $(makeLensesWith abbreviatedFields ''NodeNgramNgramPoly)
43
44
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"
52 }
53 )
54
55 queryNodeNgramNgramTable :: Query NodeNgramNgramRead
56 queryNodeNgramNgramTable = queryTable nodeNgramNgramTable
57
58 -- | not optimized (get all ngrams without filters)
59 nodeNgramNgrams :: PGS.Connection -> IO [NodeNgramNgram]
60 nodeNgramNgrams conn = runQuery conn queryNodeNgramNgramTable
61
62 instance QueryRunnerColumnDefault PGInt4 (Maybe Int) where
63 queryRunnerColumnDefault = fieldQueryRunnerColumn
64
65 instance QueryRunnerColumnDefault PGFloat8 (Maybe Double) where
66 queryRunnerColumnDefault = fieldQueryRunnerColumn