mod_storage_sql: Create a new table to hold normalized database parameters (fixes #636)
authorKim Alvefur <zash@zash.se>
Tue, 29 Nov 2016 08:20:42 +0100
changeset 7755 56abe6a8e761
parent 7754 168919a947ed
child 7756 c276d72d4e17
mod_storage_sql: Create a new table to hold normalized database parameters (fixes #636)
plugins/mod_storage_sql.lua
--- a/plugins/mod_storage_sql.lua	Mon Nov 28 07:30:39 2016 +0100
+++ b/plugins/mod_storage_sql.lua	Tue Nov 29 08:20:42 2016 +0100
@@ -433,14 +433,22 @@
 	return changes;
 end
 
+local function normalize_database(driver, database)
+	if driver == "SQLite3" and database ~= ":memory:" then
+		return resolve_relative_path(prosody.paths.data or ".", database or "prosody.sqlite");
+	end
+	return database;
+end
+
 local function normalize_params(params)
-	if params.driver == "SQLite3" then
-		if params.database ~= ":memory:" then
-			params.database = resolve_relative_path(prosody.paths.data or ".", params.database or "prosody.sqlite");
-		end
-	end
-	assert(params.driver and params.database, "Configuration error: Both the SQL driver and the database need to be specified");
-	return params;
+	return {
+		driver = assert(params.driver, "Configuration error: Both the SQL driver and the database need to be specified");
+		database = assert(normalize_database(params.driver, params.database), "Configuration error: Both the SQL driver and the database need to be specified");
+		username = params.username;
+		password = params.password;
+		host = params.host;
+		params.port;
+	};
 end
 
 function module.load()