]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/NodeNodeNgram.hs
[API][AUTH] if authorized then id of tree is given (with token).
[gargantext.git] / src / Gargantext / Database / NodeNodeNgram.hs
1 {-|
2 Module : Gargantext.Database.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
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.NodeNodeNgram where
22
23 import Prelude
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
28
29 import Opaleye
30
31
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
37 } deriving (Show)
38
39
40 type NodeNodeNgramWrite = NodeNodeNgramPoly (Column PGInt4 )
41 (Column PGInt4 )
42 (Column PGInt4 )
43 (Maybe (Column PGFloat8))
44
45 type NodeNodeNgramRead = NodeNodeNgramPoly (Column PGInt4 )
46 (Column PGInt4 )
47 (Column PGInt4 )
48 (Column PGFloat8)
49
50 type NodeNodeNgramReadNull = NodeNodeNgramPoly (Column (Nullable PGInt4 ))
51 (Column (Nullable PGInt4 ))
52 (Column (Nullable PGInt4 ))
53 (Column (Nullable PGFloat8))
54
55 type NodeNodeNgram = NodeNodeNgramPoly Int
56 Int
57 Int
58 (Maybe Double)
59
60
61 $(makeAdaptorAndInstance "pNodeNodeNgram" ''NodeNodeNgramPoly)
62 $(makeLensesWith abbreviatedFields ''NodeNodeNgramPoly)
63
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"
71 }
72 )
73
74
75 queryNodeNodeNgramTable :: Query NodeNodeNgramRead
76 queryNodeNodeNgramTable = queryTable nodeNodeNgramTable
77
78 -- | not optimized (get all ngrams without filters)
79 nodeNodeNgrams :: PGS.Connection -> IO [NodeNodeNgram]
80 nodeNodeNgrams conn = runQuery conn queryNodeNodeNgramTable
81
82 instance QueryRunnerColumnDefault PGFloat8 (Maybe Double) where
83 queryRunnerColumnDefault = fieldQueryRunnerColumn