Use additional conditions so sqlite will work or postgresql

Also added trim to prevent a trailing space from breaking the dsn string for sqlite.
Also added debug lines helpful for testing.
This commit is contained in:
FusionPBX
2023-02-07 22:50:05 -07:00
committed by GitHub
parent aacb232fc3
commit 78b4651106

View File

@@ -9,6 +9,7 @@ assert(freeswitch, "Require FreeSWITCH environment")
-----------------------------------------------------------
local FsDatabase = {} do
require "resources.functions.trim"
require "resources.functions.file_exists"
require "resources.functions.database_handle"
@@ -17,8 +18,19 @@ FsDatabase._backend_name = 'native'
function FsDatabase.new(name)
local dbh = assert(name)
if type(name) == 'string' then
dbh = database_handle(name)
if (type(name) == 'string') then
--debug information
--freeswitch.consoleLog("notice","name " .. name .. "\n");
--freeswitch.consoleLog("notice","database.type " .. database.type .. "\n");
--freeswitch.consoleLog("notice","database.name " .. database.name .. "\n");
--freeswitch.consoleLog("notice","database.path " .. database.path .. "\n");
--handle switch sqlite
if (name == 'switch' and database.type == 'sqlite' and database.path ~= nil and database.name ~= nil) then
dbh = freeswitch.Dbh("sqlite://"..trim(database.path).."/"..trim(database.name))
else
dbh = database_handle(name)
end
end
assert(dbh:connected())