]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Query/Table/Node/UpdateOpaleye.hs
[DEPS] stack upgrade
[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
26 updateHyperdata :: ToJSON a => NodeId -> a -> Cmd err Int64
27 updateHyperdata i h = mkCmd $ \c -> runUpdate_ c (updateHyperdataQuery i h)
28
29 updateHyperdataQuery :: ToJSON a => NodeId -> a -> Update Int64
30 updateHyperdataQuery i h = Update
31 { uTable = nodeTable
32 , uUpdateWith = updateEasy (\ (Node _ni _nh _nt _nu _np _nn _nd _h)
33 -> Node _ni _nh _nt _nu _np _nn _nd h'
34 )
35 , uWhere = (\row -> _node_id row .== pgNodeId i )
36 , uReturning = rCount
37 }
38 where h' = (pgJSONB $ cs $ encode $ h)
39