]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Admin/Bashql.hs
[SECURITY] password check implemented (needs tests).
[gargantext.git] / src / Gargantext / Database / Admin / Bashql.hs
1 {-# OPTIONS_GHC -fno-warn-unused-top-binds #-}
2 {-|
3 Module : Gargantext.Database.Bashql
4 Description : BASHQL to deal with Gargantext Database.
5 Copyright : (c) CNRS, 2017-Present
6 License : AGPL + CECILL v3
7 Maintainer : team@gargantext.org
8 Stability : experimental
9 Portability : POSIX
10
11 * BASHQL is a Domain Specific Language to deal with the Database
12
13 * BASHQL = functional (Bash * SQL)
14
15 * Which language to chose when working with a database ? To make it
16 simple, instead of all common Object Relational Mapping (ORM) [1]
17 strategy used nowadays inspired more by object logic than functional
18 logic, the semantics of BASHQL with focus on the function first.
19
20 * BASHQL focus on the function, i.e. use bash language function name,
21 and make it with SQL behind the scene. Then BASHQL is inspired more
22 by Bash language [2] than SQL and then follows its main commands as
23 specification and documentation.
24
25 * Main arguments:
26 1. Theoritical: database and FileSystems are each thought as a single
27 category, assumption based on theoretical work on databases by David Spivak [0].
28 2. Practical argument: basic bash commands are a daily practice among
29 developper community.
30
31 * How to help ?
32 1. Choose a command you like in Bash
33 2. Implement it in Haskell-SQL according to Gargantext Shema (Tree like
34 filesystem)
35 3. Translate it in BASHQL (follow previous implementations)
36 4. Make a pull request (enjoy the community)
37
38 * Implementation strategy: Functional adapations are made to the
39 gargantext languages options and SQL optimization are done continuously
40 during the project. For the Haskellish part, you may be inspired by
41 Turtle implementation written by Gabriel Gonzales [3] which shows how to
42 write Haskell bash translations.
43
44 * Semantics
45 - FileSystem is now a NodeSystem where each File is a Node in a Directed Graph (DG).
46
47 * References
48
49 [0] MIT Press has published "Category theory for the sciences". The book
50 can also be purchased on Amazon. Here are reviews by the MAA, by the
51 AMS, and by SIAM.
52
53 [1] https://en.wikipedia.org/wiki/Object-relational_mapping
54
55 [2] https://en.wikipedia.org/wiki/Bash_(Unix_shell)
56
57 [3] https://github.com/Gabriel439/Haskell-Turtle-Library
58
59 TODO-ACCESS: should the checks be done here or before.
60
61 -}
62
63 {-# LANGUAGE NoImplicitPrelude #-}
64 {-# LANGUAGE FlexibleContexts #-}
65 {-# LANGUAGE RankNTypes #-}
66
67 module Gargantext.Database.Admin.Bashql () {-( get
68 , ls
69 , home
70 , post
71 , del
72 , mv
73 , put
74 , rename
75 , tree
76 -- , mkCorpus, mkAnnuaire
77 )-}
78 where
79
80 import Control.Monad.Reader -- (Reader, ask)
81 import Data.Text (Text)
82 import Data.List (concat, last)
83 import Gargantext.Core.Types
84 import Gargantext.Database.Prelude (runOpaQuery, Cmd)
85 import Gargantext.Database.Schema.Node
86 import Gargantext.Database.Query.Table.Node
87 import qualified Gargantext.Database.Query.Table.Node.Update as U (Update(..), update)
88 import Gargantext.Prelude
89
90
91 -- List of NodeId
92 -- type PWD a = PWD UserId [a]
93 type PWD = [NodeId]
94 --data PWD' a = a | PWD' [a]
95
96 rename :: NodeId -> Text -> Cmd err [Int]
97 rename n t = U.update $ U.Rename n t
98
99 mv :: NodeId -> ParentId -> Cmd err [Int]
100 mv n p = U.update $ U.Move n p
101
102 -- | TODO get Children or Node
103 get :: PWD -> Cmd err [Node HyperdataAny]
104 get [] = pure []
105 get pwd = runOpaQuery $ selectNodesWithParentID (last pwd)
106
107 -- | Home, need to filter with UserId
108 {-
109 home :: Cmd err PWD
110 home = map _node_id <$> getNodesWithParentId 0 Nothing
111 -}
112
113 -- | ls == get Children
114 ls :: PWD -> Cmd err [Node HyperdataAny]
115 ls = get
116
117 tree :: PWD -> Cmd err [Node HyperdataAny]
118 tree p = do
119 ns <- get p
120 children <- mapM (\n -> get [_node_id n]) ns
121 pure $ ns <> concat children
122
123 -- | TODO
124 post :: PWD -> [NodeWrite] -> Cmd err Int64
125 post [] _ = pure 0
126 post _ [] = pure 0
127 post pth ns = insertNodesWithParent (Just $ last pth) ns
128
129 --postR :: PWD -> [NodeWrite'] -> Cmd err [Int]
130 --postR [] _ _ = pure [0]
131 --postR _ [] _ = pure [0]
132 --postR pth ns c = mkNodeR (last pth) ns c
133
134 -- | WIP
135 -- rm : mv to trash
136 -- del : empty trash
137 --rm :: PWD -> [NodeId] -> IO Int
138 --rm = del
139 del :: [NodeId] -> Cmd err Int
140 del [] = pure 0
141 del ns = deleteNodes ns
142
143 -- | TODO
144 put :: U.Update -> Cmd err [Int]
145 put = U.update
146
147 -- | TODO
148 -- cd (Home UserId) | (Node NodeId)
149 -- cd Path
150 -- jump NodeId
151 -- touch Dir
152
153 -- type Name = Text
154