All my apps use databases. The orangegstudios tip is the best option. You do not need to close it in every scene. The scene change does not interfere at all in the connection with the database.
This is an example: (do this in your main.lua file)
-- myDB is global, so you can use it in any scene
_G.myDB = nil
local sqlite3 = require( "sqlite3" )
Runtime:addEventListener("system", function(event)
if event.type == "applicationStart" then
-- Open database
local path = system.pathForFile( "assets/db/myData.db", system.ResourceDirectory )
myDB = sqlite3.open( path )
elseif event.type == "applicationExit" then
-- Close database
myDB:close()
end
end)