1 {-# OPTIONS_GHC -fno-warn-unused-top-binds #-}
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
11 * BASHQL is a Domain Specific Language to deal with the Database
13 * BASHQL = functional (Bash * SQL)
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.
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.
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
32 1. Choose a command you like in Bash
33 2. Implement it in Haskell-SQL according to Gargantext Shema (Tree like
35 3. Translate it in BASHQL (follow previous implementations)
36 4. Make a pull request (enjoy the community)
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.
45 - FileSystem is now a NodeSystem where each File is a Node in a Directed Graph (DG).
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
53 [1] https://en.wikipedia.org/wiki/Object-relational_mapping
55 [2] https://en.wikipedia.org/wiki/Bash_(Unix_shell)
57 [3] https://github.com/Gabriel439/Haskell-Turtle-Library
59 TODO-ACCESS: should the checks be done here or before.
63 {-# LANGUAGE NoImplicitPrelude #-}
64 {-# LANGUAGE FlexibleContexts #-}
65 {-# LANGUAGE RankNTypes #-}
67 module Gargantext.Database.Admin.Bashql () {-( get
76 -- , mkCorpus, mkAnnuaire
80 import Control.Monad.Reader -- (Reader, ask)
82 import Data.Text (Text)
83 import Data.List (concat, last)
85 import Gargantext.Core.Types
86 import Gargantext.Database.Admin.Utils (runOpaQuery, Cmd)
87 import Gargantext.Database.Schema.Node
88 import Gargantext.Database.Action.Query.Node
89 import qualified Gargantext.Database.Action.Query.Node.Update as U (Update(..), update)
90 import Gargantext.Prelude
94 -- type PWD a = PWD UserId [a]
96 --data PWD' a = a | PWD' [a]
98 rename :: NodeId -> Text -> Cmd err [Int]
99 rename n t = U.update $ U.Rename n t
101 mv :: NodeId -> ParentId -> Cmd err [Int]
102 mv n p = U.update $ U.Move n p
104 -- | TODO get Children or Node
105 get :: PWD -> Cmd err [Node HyperdataAny]
107 get pwd = runOpaQuery $ selectNodesWithParentID (last pwd)
109 -- | Home, need to filter with UserId
112 home = map _node_id <$> getNodesWithParentId 0 Nothing
115 -- | ls == get Children
116 ls :: PWD -> Cmd err [Node HyperdataAny]
119 tree :: PWD -> Cmd err [Node HyperdataAny]
122 children <- mapM (\n -> get [_node_id n]) ns
123 pure $ ns <> concat children
126 post :: PWD -> [NodeWrite] -> Cmd err Int64
129 post pth ns = insertNodesWithParent (Just $ last pth) ns
131 --postR :: PWD -> [NodeWrite'] -> Cmd err [Int]
132 --postR [] _ _ = pure [0]
133 --postR _ [] _ = pure [0]
134 --postR pth ns c = mkNodeR (last pth) ns c
139 --rm :: PWD -> [NodeId] -> IO Int
141 del :: [NodeId] -> Cmd err Int
143 del ns = deleteNodes ns
146 put :: U.Update -> Cmd err [Int]
150 -- cd (Home UserId) | (Node NodeId)