X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=plugins%2Fmod_storage_sql.lua;h=593acd3151813f3d05d12a51808ccf3f3a731202;hb=10ae87ff8539df0c78f2fa2161a24a43145a4cce;hp=2981013b15fc6fd0abe5fbf37aaa218e24ea0527;hpb=4801ec109cfc9486a27884940dfa6f41b397896a;p=prosody.git diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua index 2981013b..593acd31 100644 --- a/plugins/mod_storage_sql.lua +++ b/plugins/mod_storage_sql.lua @@ -33,7 +33,7 @@ local host,user,store = module.host; do -- process options to get a db connection local DBI = require "DBI"; - local params = module:get_option("sql"); + local params = module:get_option("sql") or { driver = "SQLite3", database = "prosody.sqlite" }; assert(params and params.driver and params.database, "invalid params"); prosody.unlock_globals(); @@ -47,6 +47,19 @@ do -- process options to get a db connection dbh:autocommit(false); -- don't commit automatically connection = dbh; + + if params.driver == "SQLite3" then -- auto initialize + local stmt = assert(connection:prepare("SELECT COUNT(*) FROM sqlite_master WHERE type='table' AND name='Prosody';")); + local ok = assert(stmt:execute()); + local count = stmt:fetch()[1]; + if count == 0 then + local stmt = assert(connection:prepare("CREATE TABLE Prosody (host TEXT, user TEXT, store TEXT, key TEXT, subkey TEXT, type TEXT, value TEXT);")); + assert(stmt:execute()); + assert(connection:commit()); + module:log("debug", "Initialized new SQLite3 database"); + end + --print("===", json.stringify()) + end end local function serialize(value)