]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Query/Table/ContextNodeNgrams.hs
[api] implement JSON errors
[gargantext.git] / src / Gargantext / Database / Query / Table / ContextNodeNgrams.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.ContextNodeNgrams
19 ( module Gargantext.Database.Schema.ContextNodeNgrams
20 , queryContextNodeNgramsTable
21 , insertContextNodeNgrams
22 )
23 where
24
25 import Gargantext.Database.Admin.Types.Node (pgNodeId, pgContextId)
26 import Gargantext.Database.Prelude (Cmd, mkCmd)
27 import Gargantext.Database.Schema.Ngrams (pgNgramsTypeId)
28 import Gargantext.Database.Schema.ContextNodeNgrams
29 import Gargantext.Database.Schema.Prelude
30 import Prelude
31
32
33 queryContextNodeNgramsTable :: Query ContextNodeNgramsRead
34 queryContextNodeNgramsTable = selectTable contextNodeNgramsTable
35
36 -- | Insert utils
37 insertContextNodeNgrams :: [ContextNodeNgrams] -> Cmd err Int
38 insertContextNodeNgrams = insertContextNodeNgramsW
39 . map (\(ContextNodeNgrams c n ng nt w dc) ->
40 ContextNodeNgrams (pgContextId c)
41 (pgNodeId n)
42 (sqlInt4 ng)
43 (pgNgramsTypeId nt)
44 (sqlDouble w)
45 (sqlInt4 dc)
46 )
47
48 insertContextNodeNgramsW :: [ContextNodeNgramsWrite] -> Cmd err Int
49 insertContextNodeNgramsW nnnw =
50 mkCmd $ \c -> fromIntegral <$> runInsert_ c insertNothing
51 where
52 insertNothing = Insert { iTable = contextNodeNgramsTable
53 , iRows = nnnw
54 , iReturning = rCount
55 , iOnConflict = (Just DoNothing)
56 }