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 NoImplicitPrelude #-}
13 {-# LANGUAGE QuasiQuotes #-}
14 {-# LANGUAGE OverloadedStrings #-}
17 module Gargantext.Database.Node.Update (Update(..), update) where
19 import Data.Text (Text)
20 import qualified Data.Text as DT
21 import Database.PostgreSQL.Simple
23 import Gargantext.Prelude
25 -- import Data.ByteString
26 --rename :: Connection -> NodeId -> Text -> IO ByteString
27 --rename conn nodeId name = formatQuery conn "UPDATE nodes SET name=? where id=?" (name,nodeId)
28 ------------------------------------------------------------------------
33 data Update = Rename NodeId Name
34 | Move NodeId ParentId
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
44 update :: Update -> Connection -> IO [Int]
45 update (Rename nId name) conn = map unOnly <$> query conn "UPDATE nodes SET name=? where id=? returning id"
46 (DT.take 255 name,nId)
47 update (Move nId pId) conn = map unOnly <$> query conn "UPDATE nodes SET parent_id= ? where id=? returning id"