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
12 {-# LANGUAGE FlexibleContexts #-}
13 {-# LANGUAGE NoImplicitPrelude #-}
14 {-# LANGUAGE OverloadedStrings #-}
15 {-# LANGUAGE QuasiQuotes #-}
16 {-# LANGUAGE RankNTypes #-}
19 module Gargantext.Database.Action.Query.Node.UpdateOpaleye
24 import Data.Aeson (encode, ToJSON)
25 import Gargantext.Prelude
26 import Gargantext.Database.Schema.Node
27 import Gargantext.Database.Admin.Types.Node
28 import Gargantext.Database.Admin.Utils (Cmd, mkCmd)
30 updateHyperdata :: ToJSON a => NodeId -> a -> Cmd err Int64
31 updateHyperdata i h = mkCmd $ \c -> runUpdate_ c (updateHyperdataQuery i h)
33 updateHyperdataQuery :: ToJSON a => NodeId -> a -> Update Int64
34 updateHyperdataQuery i h = Update
36 , uUpdateWith = updateEasy (\ (Node _ni _nt _nu _np _nn _nd _h)
37 -> Node _ni _nt _nu _np _nn _nd h'
39 , uWhere = (\row -> _node_id row .== pgNodeId i )
42 where h' = (pgJSONB $ cs $ encode $ h)