]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Schema/NodeNodeNgrams.hs
Merge branch 'dev-phylo' of ssh://gitlab.iscpif.fr:20022/gargantext/haskell-gargantex...
[gargantext.git] / src / Gargantext / Database / Schema / NodeNodeNgrams.hs
1 {-|
2 Module : Gargantext.Database.Schema.NodeNodeNgrams
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
8 Portability : POSIX
9
10 -}
11
12 {-# LANGUAGE NoImplicitPrelude #-}
13 {-# LANGUAGE TemplateHaskell #-}
14 {-# LANGUAGE FlexibleInstances #-}
15 {-# LANGUAGE MultiParamTypeClasses #-}
16 {-# LANGUAGE FunctionalDependencies #-}
17 {-# LANGUAGE Arrows #-}
18 {-# OPTIONS_GHC -fno-warn-orphans #-}
19
20
21 module Gargantext.Database.Schema.NodeNodeNgrams
22 where
23
24 import Prelude
25 import Data.Maybe (Maybe)
26 import Data.Profunctor.Product.TH (makeAdaptorAndInstance)
27 import Control.Lens.TH (makeLensesWith, abbreviatedFields)
28 import Gargantext.Database.Utils (Cmd, runOpaQuery)
29
30 import Opaleye
31
32
33 data NodeNodeNgramsPoly node1_id node2_id ngram_id score
34 = NodeNodeNgrams { nnng_node1_id :: node1_id
35 , nnng_node2_id :: node2_id
36 , nnng_ngrams_id :: ngram_id
37 , nnng_score :: score
38 } deriving (Show)
39
40
41 type NodeNodeNgramsWrite = NodeNodeNgramsPoly (Column PGInt4 )
42 (Column PGInt4 )
43 (Column PGInt4 )
44 (Maybe (Column PGFloat8))
45
46 type NodeNodeNgramsRead = NodeNodeNgramsPoly (Column PGInt4 )
47 (Column PGInt4 )
48 (Column PGInt4 )
49 (Column PGFloat8)
50
51 type NodeNodeNgramsReadNull = NodeNodeNgramsPoly (Column (Nullable PGInt4 ))
52 (Column (Nullable PGInt4 ))
53 (Column (Nullable PGInt4 ))
54 (Column (Nullable PGFloat8))
55
56 type NodeNodeNgrams = NodeNodeNgramsPoly Int
57 Int
58 Int
59 (Maybe Double)
60
61
62 $(makeAdaptorAndInstance "pNodeNodeNgrams" ''NodeNodeNgramsPoly)
63 $(makeLensesWith abbreviatedFields ''NodeNodeNgramsPoly)
64
65 nodeNodeNgramsTable :: Table NodeNodeNgramsWrite NodeNodeNgramsRead
66 nodeNodeNgramsTable = Table "nodes_nodes_ngrams"
67 ( pNodeNodeNgrams NodeNodeNgrams
68 { nnng_node1_id = required "node1_id"
69 , nnng_node2_id = required "node2_id"
70 , nnng_ngrams_id = required "ngram_id"
71 , nnng_score = optional "score"
72 }
73 )
74
75
76 queryNodeNodeNgramsTable :: Query NodeNodeNgramsRead
77 queryNodeNodeNgramsTable = queryTable nodeNodeNgramsTable
78
79 -- | not optimized (get all ngrams without filters)
80 nodeNodeNgrams :: Cmd err [NodeNodeNgrams]
81 nodeNodeNgrams = runOpaQuery queryNodeNodeNgramsTable
82
83 instance QueryRunnerColumnDefault PGFloat8 (Maybe Double) where
84 queryRunnerColumnDefault = fieldQueryRunnerColumn