]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Node/Update.hs
add rebranching to link distante branches
[gargantext.git] / src / Gargantext / Database / Node / Update.hs
1 {-|
2 Module : Gargantext.Database.Node.Update
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.Update (Update(..), update) where
19
20 import qualified Data.Text as DT
21 import Database.PostgreSQL.Simple
22
23 import Gargantext.Prelude
24 import Gargantext.Database.Utils
25 import Gargantext.Database.Types.Node (NodeId, ParentId)
26 import Gargantext.Database.Schema.Node (Name)
27
28 -- import Data.ByteString
29 --rename :: NodeId -> Text -> IO ByteString
30 --rename nodeId name = formatPGSQuery "UPDATE nodes SET name=? where id=?" (name,nodeId)
31 ------------------------------------------------------------------------
32
33 data Update = Rename NodeId Name
34 | Move NodeId ParentId
35
36 -- | Update a Node
37 -- TODO : Field as parameter
38 -- TODO jsonb values, consider this:
39 -- https://stackoverflow.com/questions/26703476/how-to-perform-update-operations-on-columns-of-type-jsonb-in-postgres-9-4
40
41 unOnly :: Only a -> a
42 unOnly (Only a) = a
43
44 update :: Update -> Cmd err [Int]
45 update (Rename nId name) = map unOnly <$> runPGSQuery "UPDATE nodes SET name=? where id=? returning id"
46 (DT.take 255 name,nId)
47 update (Move nId pId) = map unOnly <$> runPGSQuery "UPDATE nodes SET parent_id= ? where id=? returning id"
48 (pId, nId)
49
50