From 218dce31b824cb79863127b3eca3e248c87ffe32 Mon Sep 17 00:00:00 2001 From: Timo Smit Date: Sat, 4 Feb 2017 19:02:08 +0100 Subject: [PATCH] Added possibility to disable database system --- luascripts/db/db.lua | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/luascripts/db/db.lua b/luascripts/db/db.lua index 60729df..90c67a5 100644 --- a/luascripts/db/db.lua +++ b/luascripts/db/db.lua @@ -23,21 +23,27 @@ local db = {} local con +function db.isconnected() + return (con ~= nil) +end + -- as this module serves as a wrapper/super class, we load the selected database -- system in this function. might have to think of a better way to implement -- this, but it will suffice. function db.oninit() - if settings.get("db_type") == "mysql" then - con = require "luascripts.wolfadmin.db.mysql" - elseif settings.get("db_type") == "sqlite3" then - con = require "luascripts.wolfadmin.db.sqlite3" - else - error("invalid database system (choose mysql, sqlite3)") + if settings.get("db_type") ~= "none" then + if settings.get("db_type") == "mysql" then + con = require "luascripts.wolfadmin.db.mysql" + elseif settings.get("db_type") == "sqlite3" then + con = require "luascripts.wolfadmin.db.sqlite3" + else + error("invalid database system (choose mysql, sqlite3)") + end + + setmetatable(db, {__index = con}) + + db.start() end - - setmetatable(db, {__index = con}) - - db.start() end events.handle("onGameInit", db.oninit)