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 NoImplicitPrelude #-}
13 {-# LANGUAGE OverloadedStrings #-}
14 {-# LANGUAGE QuasiQuotes #-}
15 {-# LANGUAGE RankNTypes #-}
18 module Gargantext.Database.Node.UpdateOpaleye where
22 import Data.Aeson (encode, ToJSON)
23 import Gargantext.Prelude
24 import Gargantext.Database.Schema.Node
25 import Gargantext.Database.Types.Node
26 import Gargantext.Database.Utils (Cmd, mkCmd)
28 updateHyperdata :: ToJSON a => NodeId -> a -> Cmd err Int64
29 updateHyperdata i h = mkCmd $ \c -> runUpdate_ c (updateHyperdataQuery i h)
31 updateHyperdataQuery :: ToJSON a => NodeId -> a -> Update Int64
32 updateHyperdataQuery i h = Update
34 , uUpdateWith = updateEasy (\ (Node _ni _nt _nu _np _nn _nd _h)
35 -> Node _ni _nt _nu _np _nn _nd h'
37 , uWhere = (\row -> _node_id row .== pgNodeId i )
40 where h' = (pgJSONB $ cs $ encode $ h)