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)
29 import Gargantext.Database.Admin.Types.Node (pgNodeId)
31 updateHyperdata :: ToJSON a => NodeId -> a -> Cmd err Int64
32 updateHyperdata i h = mkCmd $ \c -> runUpdate_ c (updateHyperdataQuery i h)
34 updateHyperdataQuery :: ToJSON a => NodeId -> a -> Update Int64
35 updateHyperdataQuery i h = Update
37 , uUpdateWith = updateEasy (\ (Node _ni _nt _nu _np _nn _nd _h)
38 -> Node _ni _nt _nu _np _nn _nd h'
40 , uWhere = (\row -> _node_id row .== pgNodeId i )
43 where h' = (pgJSONB $ cs $ encode $ h)