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
12 {-# OPTIONS_GHC -fno-warn-orphans #-}
14 {-# LANGUAGE Arrows #-}
15 {-# LANGUAGE FlexibleInstances #-}
16 {-# LANGUAGE FunctionalDependencies #-}
17 {-# LANGUAGE MultiParamTypeClasses #-}
18 {-# LANGUAGE NoImplicitPrelude #-}
19 {-# LANGUAGE RankNTypes #-}
20 {-# LANGUAGE TemplateHaskell #-}
22 module Gargantext.Database.Schema.NodeNodeNgrams
26 import Data.Profunctor.Product.TH (makeAdaptorAndInstance)
27 import Control.Lens.TH (makeLenses)
28 import Gargantext.Database.Utils (Cmd, mkCmd)
29 import Gargantext.Database.Schema.Ngrams (NgramsTypeId, pgNgramsTypeId, NgramsId)
30 import Gargantext.Database.Schema.Node (pgNodeId)
31 import Gargantext.Database.Types.Node
35 data NodeNodeNgramsPoly n1 n2 ngrams_id ngt w
36 = NodeNodeNgrams { _nnng_node1_id :: n1
37 , _nnng_node2_id :: n2
38 , _nnng_ngrams_id :: ngrams_id
39 , _nnng_ngramsType :: ngt
44 type NodeNodeNgramsWrite =
45 NodeNodeNgramsPoly (Column PGInt4 )
51 type NodeNodeNgramsRead =
52 NodeNodeNgramsPoly (Column PGInt4 )
58 type NodeNodeNgramsReadNull =
59 NodeNodeNgramsPoly (Column (Nullable PGInt4 ))
60 (Column (Nullable PGInt4 ))
61 (Column (Nullable PGInt4 ))
62 (Column (Nullable PGInt4 ))
63 (Column (Nullable PGFloat8))
66 NodeNodeNgramsPoly CorpusId DocId NgramsId NgramsTypeId Double
68 $(makeAdaptorAndInstance "pNodeNodeNgrams" ''NodeNodeNgramsPoly)
69 makeLenses ''NodeNodeNgramsPoly
72 nodeNodeNgramsTable :: Table NodeNodeNgramsWrite NodeNodeNgramsRead
73 nodeNodeNgramsTable = Table "node_node_ngrams"
74 ( pNodeNodeNgrams NodeNodeNgrams
75 { _nnng_node1_id = required "node1_id"
76 , _nnng_node2_id = required "node2_id"
77 , _nnng_ngrams_id = required "ngrams_id"
78 , _nnng_ngramsType = required "ngrams_type"
79 , _nnng_weight = required "weight"
83 queryNodeNodeNgramsTable :: Query NodeNodeNgramsRead
84 queryNodeNodeNgramsTable = queryTable nodeNodeNgramsTable
88 insertNodeNodeNgrams :: [NodeNodeNgrams] -> Cmd err Int
89 insertNodeNodeNgrams = insertNodeNodeNgramsW
90 . map (\(NodeNodeNgrams n1 n2 ng nt w) ->
91 NodeNodeNgrams (pgNodeId n1)
98 insertNodeNodeNgramsW :: [NodeNodeNgramsWrite] -> Cmd err Int
99 insertNodeNodeNgramsW nnnw =
100 mkCmd $ \c -> fromIntegral <$> runInsert_ c insertNothing
102 insertNothing = (Insert { iTable = nodeNodeNgramsTable
104 , iReturning = rCount
105 , iOnConflict = (Just DoNothing)