]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Query/Table/ContextNodeNgrams2.hs
[FIX] Ngrams List size with candidates
[gargantext.git] / src / Gargantext / Database / Query / Table / ContextNodeNgrams2.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 {-# OPTIONS_GHC -fno-warn-orphans #-}
13
14 {-# LANGUAGE Arrows #-}
15 {-# LANGUAGE FunctionalDependencies #-}
16 {-# LANGUAGE TemplateHaskell #-}
17
18 module Gargantext.Database.Query.Table.ContextNodeNgrams2
19 ( module Gargantext.Database.Schema.ContextNodeNgrams2
20 , insertContextNodeNgrams2
21 , queryContextNodeNgrams2Table
22 )
23 where
24
25 import Gargantext.Database.Schema.Prelude
26 import Gargantext.Database.Schema.ContextNodeNgrams2
27 import Gargantext.Database.Admin.Types.Node (pgNodeId)
28 import Gargantext.Database.Prelude (Cmd, mkCmd)
29 import Prelude
30
31
32 queryContextNodeNgrams2Table :: Query ContextNodeNgrams2Read
33 queryContextNodeNgrams2Table = selectTable contextNodeNgrams2Table
34
35 -- | Insert utils
36 insertContextNodeNgrams2 :: [ContextNodeNgrams2] -> Cmd err Int
37 insertContextNodeNgrams2 = insertContextNodeNgrams2W
38 . map (\(ContextNodeNgrams2 n1 n2 w) ->
39 ContextNodeNgrams2 (pgNodeId n1)
40 (sqlInt4 n2)
41 (sqlDouble w)
42 )
43
44 insertContextNodeNgrams2W :: [ContextNodeNgrams2Write] -> Cmd err Int
45 insertContextNodeNgrams2W nnnw =
46 mkCmd $ \c -> fromIntegral <$> runInsert_ c insertNothing
47 where
48 insertNothing = Insert { iTable = contextNodeNgrams2Table
49 , iRows = nnnw
50 , iReturning = rCount
51 , iOnConflict = (Just DoNothing)
52 }