]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Action/Query/Node/UpdateOpaleye.hs
[DB] refactoring
[gargantext.git] / src / Gargantext / Database / Action / Query / 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.Action.Query.Node.UpdateOpaleye
20 where
21
22
23 import Opaleye
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)
30
31 updateHyperdata :: ToJSON a => NodeId -> a -> Cmd err Int64
32 updateHyperdata i h = mkCmd $ \c -> runUpdate_ c (updateHyperdataQuery i h)
33
34 updateHyperdataQuery :: ToJSON a => NodeId -> a -> Update Int64
35 updateHyperdataQuery i h = Update
36 { uTable = nodeTable
37 , uUpdateWith = updateEasy (\ (Node _ni _nt _nu _np _nn _nd _h)
38 -> Node _ni _nt _nu _np _nn _nd h'
39 )
40 , uWhere = (\row -> _node_id row .== pgNodeId i )
41 , uReturning = rCount
42 }
43 where h' = (pgJSONB $ cs $ encode $ h)
44