]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Query/Table/Node/Update.hs
Merge branch 'dev-tree-reload' of ssh://gitlab.iscpif.fr:20022/gargantext/haskell...
[gargantext.git] / src / Gargantext / Database / Query / Table / 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 QuasiQuotes #-}
13
14 module Gargantext.Database.Query.Table.Node.Update (Update(..), update)
15 where
16
17 import qualified Data.Text as DT
18 import Database.PostgreSQL.Simple
19
20 import Gargantext.Prelude
21 import Gargantext.Core.Types (Name)
22 import Gargantext.Database.Prelude
23 import Gargantext.Database.Admin.Types.Node (NodeId, ParentId)
24
25 -- import Data.ByteString
26 --rename :: NodeId -> Text -> IO ByteString
27 --rename nodeId name = formatPGSQuery "UPDATE nodes SET name=? where id=?" (name,nodeId)
28 ------------------------------------------------------------------------
29
30 data Update = Rename NodeId Name
31 | Move NodeId ParentId
32
33 -- | Update a Node
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
37
38 unOnly :: Only a -> a
39 unOnly (Only a) = a
40
41 -- TODO-ACCESS
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"
46 (pId, nId)
47
48