@@ -2,95 +2,95 @@ DB2Rest = {}
22DB2Rest .__index = DB2Rest
33
44function DB2Rest .new (db_config )
5- local self = setmetatable ({}, DB2Rest )
6- self ._db_config = db_config
7- self ._restApiUrl = db_config [" url" ] .. db_config [" db_name" ] .. " /"
5+ local self = setmetatable ({}, DB2Rest )
6+ self ._db_config = db_config
7+ self ._restApiUrl = db_config [" url" ] .. db_config [" db_name" ] .. " /"
88
9- return self
9+ return self
1010end
1111
1212function DB2Rest :read (collection , params , body )
13- params = params or {}
14- params [' filters' ] = params [' filters' ] or {}
15- params [' sort' ] = params [' sort' ] or {}
16- params [' fields' ] = params [' fields' ] or {}
13+ params = params or {}
14+ params [' filters' ] = params [' filters' ] or {}
15+ params [' sort' ] = params [' sort' ] or {}
16+ params [' fields' ] = params [' fields' ] or {}
1717
18- local filter = " ?filter=" .. table.concat (params [' filters' ], " ;" )
19- filter = filter .. " &sort=" .. table.concat (params [' sort' ], " ;" )
20- filter = filter .. " &fields=" .. table.concat (params [' fields' ], " ," )
18+ local filter = " ?filter=" .. table.concat (params [' filters' ], " ;" )
19+ filter = filter .. " &sort=" .. table.concat (params [' sort' ], " ;" )
20+ filter = filter .. " &fields=" .. table.concat (params [' fields' ], " ," )
2121
22- local method = " GET"
23- local expand = " "
22+ local method = " GET"
23+ local expand = " "
2424
25- local request_params = {
26- method = method ,
27- headers = {
28- [" Content-Type" ] = " application/json"
29- }
30- }
25+ local request_params = {
26+ method = method ,
27+ headers = {
28+ [" Content-Type" ] = " application/json"
29+ }
30+ }
3131
32- if body then
33- request_params .body = EncodeJson (body ) or " "
34- method = " POST"
35- expand = " /_expand"
36- end
32+ if body then
33+ request_params .body = EncodeJson (body ) or " "
34+ method = " POST"
35+ expand = " /_expand"
36+ end
3737
38- local ok , h , body =
39- Fetch (
40- self ._restApiUrl .. collection .. expand .. filter ,
41- request_params
42- )
43- return DecodeJson (body )
38+ local ok , h , body =
39+ Fetch (
40+ self ._restApiUrl .. collection .. expand .. filter ,
41+ request_params
42+ )
43+ return DecodeJson (body )
4444end
4545
4646function DB2Rest :write (collection , params )
47- local ok , h , body =
48- Fetch (
49- self ._restApiUrl .. collection .. filter ,
50- {
51- method = " POST" ,
52- body = EncodeJson (params ) or " " ,
53- headers = {
54- [" Content-Type" ] = " application/json"
55- }
56- }
57- )
58- return DecodeJson (body )
47+ local ok , h , body =
48+ Fetch (
49+ self ._restApiUrl .. collection .. filter ,
50+ {
51+ method = " POST" ,
52+ body = EncodeJson (params ) or " " ,
53+ headers = {
54+ [" Content-Type" ] = " application/json"
55+ }
56+ }
57+ )
58+ return DecodeJson (body )
5959end
6060
6161function DB2Rest :delete (collection , params )
62- local ok , h , body =
63- Fetch (
64- self ._restApiUrl .. collection .. filter ,
65- {
66- method = " DELETE" ,
67- body = EncodeJson (params ) or " " ,
68- headers = {
69- [" Content-Type" ] = " application/json"
70- }
71- }
72- )
73- return DecodeJson (body )
62+ local ok , h , body =
63+ Fetch (
64+ self ._restApiUrl .. collection .. filter ,
65+ {
66+ method = " DELETE" ,
67+ body = EncodeJson (params ) or " " ,
68+ headers = {
69+ [" Content-Type" ] = " application/json"
70+ }
71+ }
72+ )
73+ return DecodeJson (body )
7474end
7575
7676function DB2Rest :update (collection , filters , params )
77- local filter = " "
78- if type (filters ) == " table" then
79- filter = " ?filter=" .. table.concat (filters , " ;" )
80- end
77+ local filter = " "
78+ if type (filters ) == " table" then
79+ filter = " ?filter=" .. table.concat (filters , " ;" )
80+ end
8181
82- local ok , h , body =
83- Fetch (
84- self ._restApiUrl .. collection .. filter ,
85- {
86- method = " PUT" ,
87- body = EncodeJson (params ) or " " ,
88- headers = {
89- [" Content-Type" ] = " application/json"
90- }
91- }
92- )
93- return DecodeJson (body )
82+ local ok , h , body =
83+ Fetch (
84+ self ._restApiUrl .. collection .. filter ,
85+ {
86+ method = " PUT" ,
87+ body = EncodeJson (params ) or " " ,
88+ headers = {
89+ [" Content-Type" ] = " application/json"
90+ }
91+ }
92+ )
93+ return DecodeJson (body )
9494end
9595
9696return DB2Rest
0 commit comments