aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2023-01-19 16:56:12 +0100
committerKim Alvefur <zash@zash.se>2023-01-19 16:56:12 +0100
commit4c14111c76c2c14eb49ecdb5398e4739bd6b5b13 (patch)
tree756aa1052bbb0d76ff4d5b2226f651b81923b626
parent2dada39e39863f29e64129395057fb07e4ee6046 (diff)
downloadprosody-4c14111c76c2c14eb49ecdb5398e4739bd6b5b13.tar.gz
prosody-4c14111c76c2c14eb49ecdb5398e4739bd6b5b13.zip
mod_storage_sql: Support SQLite3 without LuaDBI
-rw-r--r--CHANGES1
-rw-r--r--plugins/mod_storage_sql.lua9
2 files changed, 9 insertions, 1 deletions
diff --git a/CHANGES b/CHANGES
index 12f67082..5ee3b66b 100644
--- a/CHANGES
+++ b/CHANGES
@@ -34,6 +34,7 @@ TRUNK
- Support sub-second precision timestamps
- mod_blocklist: New option 'migrate_legacy_blocking' to disable migration from mod_privacy
+- Ability to use SQLite3 storage using LuaSQLite3 instead of LuaDBI
## Removed
diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua
index 982ddada..45fda70d 100644
--- a/plugins/mod_storage_sql.lua
+++ b/plugins/mod_storage_sql.lua
@@ -1,9 +1,11 @@
-- luacheck: ignore 212/self
+local deps = require "util.dependencies";
local cache = require "util.cache";
local json = require "util.json";
-local sql = require "util.sql";
+local sqlite = deps.softreq "util.sqlite3";
+local dbisql = (sqlite and deps.softreq or require) "util.sql";
local xml_parse = require "util.xml".parse;
local uuid = require "util.uuid";
local resolve_relative_path = require "util.paths".resolve_relative_path;
@@ -692,6 +694,7 @@ end
local function create_table(engine) -- luacheck: ignore 431/engine
+ local sql = engine.params.driver == "SQLite3" and sqlite or dbisql;
local Table, Column, Index = sql.Table, sql.Column, sql.Index;
local ProsodyTable = Table {
@@ -732,6 +735,7 @@ end
local function upgrade_table(engine, params, apply_changes) -- luacheck: ignore 431/engine
local changes = false;
if params.driver == "MySQL" then
+ local sql = dbisql;
local success,err = engine:transaction(function()
do
local result = assert(engine:execute("SHOW COLUMNS FROM \"prosody\" WHERE \"Field\"='value' and \"Type\"='text'"));
@@ -831,6 +835,7 @@ end
function module.load()
local engines = module:shared("/*/sql/connections");
local params = normalize_params(module:get_option("sql", default_params));
+ local sql = params.driver == "SQLite3" and sqlite or dbisql;
local db_uri = sql.db2uri(params);
engine = engines[db_uri];
if not engine then
@@ -869,6 +874,7 @@ function module.command(arg)
local uris = {};
for host in pairs(prosody.hosts) do -- luacheck: ignore 431/host
local params = normalize_params(config.get(host, "sql") or default_params);
+ local sql = engine.params.driver == "SQLite3" and sqlite or dbisql;
uris[sql.db2uri(params)] = params;
end
print("We will check and upgrade the following databases:\n");
@@ -884,6 +890,7 @@ function module.command(arg)
-- Upgrade each one
for _, params in pairs(uris) do
print("Checking "..params.database.."...");
+ local sql = params.driver == "SQLite3" and sqlite or dbisql;
engine = sql:create_engine(params);
upgrade_table(engine, params, true);
end