Software /
code /
prosody
Comparison
plugins/mod_storage_sql.lua @ 12872:a20923f7d5fd
mod_storage_sql: Record connection to database as module status
Allows retrieving this in e.g. a health reporting module
Thanks pfak
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 30 Jan 2023 00:38:26 +0100 |
parent | 12846:1638991caed2 |
child | 12873:7f4f834fae79 |
comparison
equal
deleted
inserted
replaced
12871:885323e2a1ce | 12872:a20923f7d5fd |
---|---|
838 local sql = params.driver == "SQLite3" and sqlite or dbisql; | 838 local sql = params.driver == "SQLite3" and sqlite or dbisql; |
839 local db_uri = sql.db2uri(params); | 839 local db_uri = sql.db2uri(params); |
840 engine = engines[db_uri]; | 840 engine = engines[db_uri]; |
841 if not engine then | 841 if not engine then |
842 module:log("debug", "Creating new engine %s", db_uri); | 842 module:log("debug", "Creating new engine %s", db_uri); |
843 module:log_status("debug", "Creating new engine for "..params.driver); | |
843 engine = sql:create_engine(params, function (engine) -- luacheck: ignore 431/engine | 844 engine = sql:create_engine(params, function (engine) -- luacheck: ignore 431/engine |
844 if module:get_option("sql_manage_tables", true) then | 845 if module:get_option("sql_manage_tables", true) then |
845 -- Automatically create table, ignore failure (table probably already exists) | 846 -- Automatically create table, ignore failure (table probably already exists) |
846 -- FIXME: we should check in information_schema, etc. | 847 -- FIXME: we should check in information_schema, etc. |
847 create_table(engine); | 848 create_table(engine); |
856 if row[1] == "ENABLE_UPDATE_DELETE_LIMIT" then | 857 if row[1] == "ENABLE_UPDATE_DELETE_LIMIT" then |
857 engine._have_delete_limit = true; | 858 engine._have_delete_limit = true; |
858 end | 859 end |
859 end | 860 end |
860 end | 861 end |
862 module:set_status("info", "Connected to " .. engine.params.driver); | |
863 end, function (engine) | |
864 module:set_status("error", "Disconnected from " .. engine.params.driver); | |
861 end); | 865 end); |
862 engines[sql.db2uri(params)] = engine; | 866 engines[sql.db2uri(params)] = engine; |
867 else | |
868 module:set_status("info", "Using existing engine"); | |
863 end | 869 end |
864 | 870 |
865 module:provides("storage", driver); | 871 module:provides("storage", driver); |
866 end | 872 end |
867 | 873 |