]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Query/Table/NodeNodeNgrams2.hs
[DB/FACT] Gargantext.Database.Prelude
[gargantext.git] / src / Gargantext / Database / Query / Table / NodeNodeNgrams2.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 FlexibleContexts #-}
16 {-# LANGUAGE FlexibleInstances #-}
17 {-# LANGUAGE FunctionalDependencies #-}
18 {-# LANGUAGE MultiParamTypeClasses #-}
19 {-# LANGUAGE NoImplicitPrelude #-}
20 {-# LANGUAGE RankNTypes #-}
21 {-# LANGUAGE TemplateHaskell #-}
22
23 module Gargantext.Database.Query.Table.NodeNodeNgrams2
24 ( module Gargantext.Database.Schema.NodeNodeNgrams2
25 , insertNodeNodeNgrams2
26 )
27 where
28
29 import Gargantext.Database.Schema.Prelude
30 import Gargantext.Database.Schema.NodeNodeNgrams2
31 import Gargantext.Database.Admin.Types.Node (pgNodeId)
32 import Gargantext.Database.Prelude (Cmd, mkCmd)
33 import Prelude
34
35
36 _queryNodeNodeNgrams2Table :: Query NodeNodeNgrams2Read
37 _queryNodeNodeNgrams2Table = queryTable nodeNodeNgrams2Table
38
39 -- | Insert utils
40 insertNodeNodeNgrams2 :: [NodeNodeNgrams2] -> Cmd err Int
41 insertNodeNodeNgrams2 = insertNodeNodeNgrams2W
42 . map (\(NodeNodeNgrams2 n1 n2 w) ->
43 NodeNodeNgrams2 (pgNodeId n1)
44 (pgInt4 n2)
45 (pgDouble w)
46 )
47
48 insertNodeNodeNgrams2W :: [NodeNodeNgrams2Write] -> Cmd err Int
49 insertNodeNodeNgrams2W nnnw =
50 mkCmd $ \c -> fromIntegral <$> runInsert_ c insertNothing
51 where
52 insertNothing = Insert { iTable = nodeNodeNgrams2Table
53 , iRows = nnnw
54 , iReturning = rCount
55 , iOnConflict = (Just DoNothing)
56 }