]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Query/Table/ContextNodeNgrams.hs
add default weight
[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) ->
40 ContextNodeNgrams (pgContextId c)
41 (pgNodeId n)
42 (sqlInt4 ng)
43 (pgNgramsTypeId nt)
44 (sqlDouble w)
45 )
46
47 insertContextNodeNgramsW :: [ContextNodeNgramsWrite] -> Cmd err Int
48 insertContextNodeNgramsW nnnw =
49 mkCmd $ \c -> fromIntegral <$> runInsert_ c insertNothing
50 where
51 insertNothing = Insert { iTable = contextNodeNgramsTable
52 , iRows = nnnw
53 , iReturning = rCount
54 , iOnConflict = (Just DoNothing)
55 }