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.Node.UpdateOpaleye where
23 import Data.Aeson (encode, ToJSON)
24 import Gargantext.Prelude
25 import Gargantext.Database.Schema.Node
26 import Gargantext.Database.Types.Node
27 import Gargantext.Database.Utils (Cmd, mkCmd)
29 updateHyperdata :: ToJSON a => NodeId -> a -> Cmd err Int64
30 updateHyperdata i h = mkCmd $ \c -> runUpdate_ c (updateHyperdataQuery i h)
32 updateHyperdataQuery :: ToJSON a => NodeId -> a -> Update Int64
33 updateHyperdataQuery i h = Update
35 , uUpdateWith = updateEasy (\ (Node _ni _nt _nu _np _nn _nd _h)
36 -> Node _ni _nt _nu _np _nn _nd h'
38 , uWhere = (\row -> _node_id row .== pgNodeId i )
41 where h' = (pgJSONB $ cs $ encode $ h)