]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Query/Table/NodeNodeNgrams.hs
Merge branch 'dev' into 86-dev-graphql
[gargantext.git] / src / Gargantext / Database / Query / Table / NodeNodeNgrams.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.NodeNodeNgrams
19 ( module Gargantext.Database.Schema.NodeNodeNgrams
20 , queryNodeNodeNgramsTable
21 , insertNodeNodeNgrams
22 )
23 where
24
25 import Gargantext.Database.Admin.Types.Node (pgNodeId)
26 import Gargantext.Database.Prelude (Cmd, mkCmd)
27 import Gargantext.Database.Schema.Ngrams (pgNgramsTypeId)
28 import Gargantext.Database.Schema.NodeNodeNgrams
29 import Gargantext.Database.Schema.Prelude
30 import Prelude
31
32
33 queryNodeNodeNgramsTable :: Query NodeNodeNgramsRead
34 queryNodeNodeNgramsTable = selectTable nodeNodeNgramsTable
35
36 -- | Insert utils
37 insertNodeNodeNgrams :: [NodeNodeNgrams] -> Cmd err Int
38 insertNodeNodeNgrams = insertNodeNodeNgramsW
39 . map (\(NodeNodeNgrams n1 n2 ng nt w) ->
40 NodeNodeNgrams (pgNodeId n1)
41 (pgNodeId n2)
42 (sqlInt4 ng)
43 (pgNgramsTypeId nt)
44 (pgDouble w)
45 )
46
47 insertNodeNodeNgramsW :: [NodeNodeNgramsWrite] -> Cmd err Int
48 insertNodeNodeNgramsW nnnw =
49 mkCmd $ \c -> fromIntegral <$> runInsert_ c insertNothing
50 where
51 insertNothing = (Insert { iTable = nodeNodeNgramsTable
52 , iRows = nnnw
53 , iReturning = rCount
54 , iOnConflict = (Just DoNothing)
55 })
56