Skip to content

Commit df1cf96

Browse files
author
Olivier Bonnaure
committed
feat: arangodb driver clean code
1 parent 8c1550c commit df1cf96

File tree

4 files changed

+13
-21
lines changed

4 files changed

+13
-21
lines changed

.lua/arangodb.lua

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
Adb = {}
22
Adb.__index = Adb
33

4-
function Adb.new()
4+
function Adb.new(db_config)
55
local self = setmetatable({}, Adb)
66

77
self._lastDBConnect = GetTime()
8+
self._db_config = db_config
89
self._arangoAPI = ""
910
self._arangoJWT = ""
10-
self._db_config = null
11+
12+
self:Auth()
1113

1214
return self
1315
end
@@ -16,11 +18,6 @@ function Adb:Api_url(path)
1618
return self._arangoAPI .. path
1719
end
1820

19-
function Adb:infos()
20-
print(self._arangoAPI)
21-
print(self._arangoJWT)
22-
end
23-
2421
function Adb:Api_run(path, method, params, headers)
2522
params = params or {}
2623
headers = headers or {}
@@ -36,22 +33,18 @@ function Adb:Api_run(path, method, params, headers)
3633
return DecodeJson(body), ok, h
3734
end
3835

39-
function Adb:Auth(db_config)
40-
print(EncodeJson(db_config))
41-
if self._db_config == null then self._db_config = db_config end
42-
36+
function Adb:Auth()
4337
local ok, headers, body =
4438
Fetch(
45-
db_config.url .. "/_open/auth",
39+
self._db_config.url .. "/_open/auth",
4640
{
4741
method = "POST",
4842
body = '{ "username": "' .. self._db_config.username .. '", "password": "' .. self._db_config.password .. '" }'
4943
}
5044
)
5145

5246
self._arangoAPI = self._db_config.url .. "/_db/" .. self._db_config.db_name .. "/_api"
53-
print(self._arangoAPI)
54-
print(BeansEnv)
47+
5548
if ok == 200 then
5649
self._arangoJWT = DecodeJson(body)["jwt"]
5750
end

.lua/luaonbeans.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,8 @@ function InitDB(db_config)
349349
PGRest[config.name] = _PGRest
350350
elseif (config.engine == "arangodb") then
351351
local _Adb = require("arangodb")
352-
local adb_driver = _Adb.new()
353-
adb_driver:Auth(config)
352+
local adb_driver = _Adb.new(config)
353+
adb_driver:Auth()
354354
adb_driver:UpdateCacheConfiguration({ mode = "on" })
355355
Adb[config.name] = adb_driver
356356
elseif (config.engine == "db2rest") then

beans.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,15 @@ SetupArangoDB = function(env)
122122
Adb = {}
123123
_Adb = require "arangodb"
124124
for _, config in pairs(DBConfig[BeansEnv]) do
125-
local adb_driver = _Adb.new()
126-
adb_driver:Auth(config)
125+
local adb_driver = _Adb.new(config)
126+
adb_driver:Auth()
127127
Adb[config.name] = adb_driver
128128
end
129129

130130
if DBConfig["system"] then
131131
_Adb = require "arangodb"
132-
local adb_driver = _Adb.new()
133-
adb_driver:Auth(DBConfig["system"])
132+
local adb_driver = _Adb.new(DBConfig["system"])
133+
adb_driver:Auth()
134134
Adb.system = adb_driver
135135
end
136136

specs/arangodb_spec.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ return {
2626

2727
describe("CreateDocument", function()
2828
it("create document", function()
29-
print(Adb.primary:infos())
3029
local collection = Adb.primary:CreateCollection("test_data")
3130
expect.truthy(collection.code == 200)
3231

0 commit comments

Comments
 (0)