]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Query/Table/Node/UpdateOpaleye.hs
[ngrams] add r_history %~ mempty to ngrams POST
[gargantext.git] / src / Gargantext / Database / Query / Table / Node / UpdateOpaleye.hs
1 {-|
2 Module : Gargantext.Database.Node.UpdateOpaleye
3 Description : Update Node in Database (Postgres)
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 {-# LANGUAGE QuasiQuotes #-}
13
14
15 module Gargantext.Database.Query.Table.Node.UpdateOpaleye
16 where
17
18
19 import Opaleye
20 import Data.Aeson (encode, ToJSON)
21 import Gargantext.Prelude
22 import Gargantext.Database.Schema.Node
23 import Gargantext.Database.Admin.Types.Node
24 import Gargantext.Database.Prelude (Cmd, mkCmd)
25 import Gargantext.Database.Admin.Types.Node (pgNodeId)
26
27 updateHyperdata :: ToJSON a => NodeId -> a -> Cmd err Int64
28 updateHyperdata i h = mkCmd $ \c -> runUpdate_ c (updateHyperdataQuery i h)
29
30 updateHyperdataQuery :: ToJSON a => NodeId -> a -> Update Int64
31 updateHyperdataQuery i h = Update
32 { uTable = nodeTable
33 , uUpdateWith = updateEasy (\ (Node _ni _nt _nu _np _nn _nd _h)
34 -> Node _ni _nt _nu _np _nn _nd h'
35 )
36 , uWhere = (\row -> _node_id row .== pgNodeId i )
37 , uReturning = rCount
38 }
39 where h' = (pgJSONB $ cs $ encode $ h)
40