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