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
12 {-# LANGUAGE QuasiQuotes #-}
14 module Gargantext.Database.Query.Table.Node.Update (Update(..), update)
17 import qualified Data.Text as DT
18 import Database.PostgreSQL.Simple
20 import Gargantext.Prelude
21 import Gargantext.Core.Types (Name)
22 import Gargantext.Database.Prelude
23 import Gargantext.Database.Admin.Types.Node (NodeId, ParentId)
25 -- import Data.ByteString
26 --rename :: NodeId -> Text -> IO ByteString
27 --rename nodeId name = formatPGSQuery "UPDATE nodes SET name=? where id=?" (name,nodeId)
28 ------------------------------------------------------------------------
30 data Update = Rename NodeId Name
31 | Move NodeId ParentId
34 -- TODO : Field as parameter
35 -- TODO jsonb values, consider this:
36 -- https://stackoverflow.com/questions/26703476/how-to-perform-update-operations-on-columns-of-type-jsonb-in-postgres-9-4
42 update :: Update -> Cmd err [Int]
43 update (Rename nId name) = map unOnly <$> runPGSQuery "UPDATE nodes SET name=? where id=? returning id"
44 (DT.take 255 name,nId)
45 update (Move nId pId) = map unOnly <$> runPGSQuery "UPDATE nodes SET parent_id= ? where id=? returning id"