blob: bfbd637374f64c9e66aacc1b041c45e17b73f60c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
{-# LANGUAGE OverloadedStrings #-}
module ACMS.API.REST.Collection where
import Data.Aeson qualified as A
import Data.Aeson.KeyMap qualified as AM
import Data.ByteString.Lazy.UTF8 qualified as LB
import Data.Function ((&))
import Data.Text qualified as T
import Network.HTTP.Simple
import Text.Printf (printf)
type CollectionName = T.Text
list :: T.Text -> IO [A.Object]
list c =
"http://localhost:8081"
& setRequestMethod "POST"
& setRequestBodyLBS (LB.fromString (printf "SELECT %s FROM %s" c c))
& httpLBS
>>= A.throwDecode . getResponseBody
read :: T.Text -> T.Text -> IO [A.Object]
read c i =
"http://localhost:8081"
& setRequestMethod "POST"
& setRequestBodyLBS
(LB.fromString (printf "SELECT %s FROM %s WHERE %s.$fileName == \"%s\"" c c c i))
& httpLBS
>>= A.throwDecode . getResponseBody
update :: T.Text -> T.Text -> A.Object -> IO ()
update c i o =
"http://localhost:8081"
& setRequestMethod "POST"
& setRequestBodyLBS
(LB.fromString (printf "UPDATE %s SET %s WHERE %s.$fileName == \"%s\"" c (LB.toString (A.encode o)) c i))
& httpLBS
>>= A.throwDecode . getResponseBody
create :: T.Text -> T.Text -> A.Object -> IO ()
create c i o =
"http://localhost:8081"
& setRequestMethod "POST"
& setRequestBodyLBS
(LB.fromString (printf "INSERT %s INTO %s" (LB.toString (A.encode (AM.insert "$fileName" (A.String i) o))) c))
& httpLBS
>>= A.throwDecode . getResponseBody
delete :: T.Text -> T.Text -> IO [A.Object]
delete c i =
"http://localhost:8081"
& setRequestMethod "POST"
& setRequestBodyLBS
(LB.fromString (printf "DELETE FROM %s WHERE %s.$fileName == \"%s\"" c c i))
& httpLBS
>>= A.throwDecode . getResponseBody
|