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.Maybe (Maybe)
27 import Data.Profunctor.Product.TH (makeAdaptorAndInstance)
28 --import Control.Lens.TH (makeLensesWith, abbreviatedFields)
29 import Gargantext.Database.Utils (Cmd, mkCmd)
30 import Gargantext.Database.Schema.Ngrams (NgramsTypeId, pgNgramsTypeId, NgramsId)
31 import Gargantext.Database.Schema.Node (pgNodeId)
32 import Gargantext.Database.Types.Node
37 data NodeNodeNgramsPoly id' n1 n2 ngrams_id ngt w
38 = NodeNodeNgrams { nnng_id :: id'
41 , nnng_ngrams_id :: ngrams_id
42 , nnng_ngramsType :: ngt
47 type NodeNodeNgramsWrite =
48 NodeNodeNgramsPoly (Maybe (Column PGInt4 ))
55 type NodeNodeNgramsRead =
56 NodeNodeNgramsPoly (Column PGInt4 )
63 type NodeNodeNgramsReadNull =
64 NodeNodeNgramsPoly (Column (Nullable PGInt4 ))
65 (Column (Nullable PGInt4 ))
66 (Column (Nullable PGInt4 ))
67 (Column (Nullable PGInt4 ))
68 (Column (Nullable PGInt4 ))
69 (Column (Nullable PGFloat8))
72 NodeNodeNgramsPoly (Maybe Int) CorpusId DocId NgramsId NgramsTypeId Double
75 $(makeAdaptorAndInstance "pNodeNodeNgrams" ''NodeNodeNgramsPoly)
76 -- $(makeLensesWith abbreviatedFields ''NodeNodeNgramsPoly)
78 nodeNodeNgramsTable :: Table NodeNodeNgramsWrite NodeNodeNgramsRead
79 nodeNodeNgramsTable = Table "node_node_ngrams"
80 ( pNodeNodeNgrams NodeNodeNgrams
81 { nnng_id = optional "id"
82 , nnng_node1_id = required "node1_id"
83 , nnng_node2_id = required "node2_id"
84 , nnng_ngrams_id = required "ngrams_id"
85 , nnng_ngramsType = required "ngrams_type"
86 , nnng_weight = required "weight"
90 queryNodeNodeNgramsTable :: Query NodeNodeNgramsRead
91 queryNodeNodeNgramsTable = queryTable nodeNodeNgramsTable
95 insertNodeNodeNgrams :: [NodeNodeNgrams] -> Cmd err Int
96 insertNodeNodeNgrams = insertNodeNodeNgramsW
97 . map (\(NodeNodeNgrams id'' n1 n2 ng nt w) ->
98 NodeNodeNgrams (pgInt4 <$> id'')
106 insertNodeNodeNgramsW :: [NodeNodeNgramsWrite] -> Cmd err Int
107 insertNodeNodeNgramsW nnnw =
108 mkCmd $ \c -> fromIntegral <$> runInsert_ c insertNothing
110 insertNothing = (Insert { iTable = nodeNodeNgramsTable
112 , iReturning = rCount
113 , iOnConflict = (Just DoNothing)