]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Node/UpdateOpaleye.hs
bug fix
[gargantext.git] / src / Gargantext / Database / 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 NoImplicitPrelude #-}
13 {-# LANGUAGE OverloadedStrings #-}
14 {-# LANGUAGE QuasiQuotes #-}
15 {-# LANGUAGE RankNTypes #-}
16
17
18 module Gargantext.Database.Node.UpdateOpaleye where
19
20
21 import Opaleye
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)
27
28 updateHyperdata :: ToJSON a => NodeId -> a -> Cmd err Int64
29 updateHyperdata i h = mkCmd $ \c -> runUpdate_ c (updateHyperdataQuery i h)
30
31 updateHyperdataQuery :: ToJSON a => NodeId -> a -> Update Int64
32 updateHyperdataQuery i h = Update
33 { uTable = nodeTable
34 , uUpdateWith = updateEasy (\ (Node _ni _nt _nu _np _nn _nd _h)
35 -> Node _ni _nt _nu _np _nn _nd h'
36 )
37 , uWhere = (\row -> _node_id row .== pgNodeId i )
38 , uReturning = rCount
39 }
40 where h' = (pgJSONB $ cs $ encode $ h)
41