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