-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinit.lua
68 lines (55 loc) · 1.54 KB
/
init.lua
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
57
58
59
60
61
62
63
64
65
66
67
68
local connect = require('connect')
local reql = require('Utils/reql.lua')
local emitter = require('Utils/emitter.lua')
local cmanager = require('Utils/coroutinemanager.lua')
local logger_f = require('Utils/logger.lua')
-- Default options table || Do NOT edit, pass your options to the function instead
local default = {
address = 'http://127.0.0.1',
port = 28015,
user = 'admin',
password = '',
db = 'test',
reconnect = false,
reusable = false,
debug = false,
quiet = false,
file = 'luvitreql.log',
}
local format = string.format
local find = string.find
return {
connect = function(options, callback)
local logger = logger_f()
options = options and options or {}
local type = type(options)
if type == 'function' then
callback = options
options, type = { }, 'table'
end
if type ~= 'table' then
return logger:harderr(format('bad argument #1 to \'connect\' (table expected, got %s)', type))
end
for k, v in pairs(default) do
if options[k] == nil then
options[k] = v
end
end
logger.options = options
logger:setFile(options.file)
if options.address:sub(#options.address) == '/' then
options.address = options.address:sub(1, #options.address - 1)
end
if not find(options.address, 'https?', 1) == 1 then
logger:warn('Procotol not supplied, defaulting to http://')
options.address = format('http://%s', options.address)
end
return connect(options, callback, logger)
end,
reql = function()
return reql()
end,
emitter = emitter,
logger = logger_f(),
_cmanager = cmanager
}