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