Comparison

plugins/mod_storage_sql.lua @ 13241:0419de4e4db1

mod_storage_sql: Pass variables as arguments instead of upvalues Probably a workaround for the lack of argument passing when using xpcall in Lua 5.1, no longer relevant.
author Kim Alvefur <zash@zash.se>
date Sat, 22 Jul 2023 15:22:54 +0200
parent 13229:bb7177efbf41
child 13242:0d3881bf29a8
comparison
equal deleted inserted replaced
13240:a378937103cb 13241:0419de4e4db1
59 end 59 end
60 return nil, "Unhandled value type: "..t; 60 return nil, "Unhandled value type: "..t;
61 end 61 end
62 62
63 local host = module.host; 63 local host = module.host;
64 local user, store; 64
65 65 local function keyval_store_get(user, store)
66 local function keyval_store_get()
67 local haveany; 66 local haveany;
68 local result = {}; 67 local result = {};
69 local select_sql = [[ 68 local select_sql = [[
70 SELECT "key","type","value" 69 SELECT "key","type","value"
71 FROM "prosody" 70 FROM "prosody"
86 end 85 end
87 if haveany then 86 if haveany then
88 return result; 87 return result;
89 end 88 end
90 end 89 end
91 local function keyval_store_set(data) 90 local function keyval_store_set(data, user, store)
92 local delete_sql = [[ 91 local delete_sql = [[
93 DELETE FROM "prosody" 92 DELETE FROM "prosody"
94 WHERE "host"=? AND "user"=? AND "store"=? 93 WHERE "host"=? AND "user"=? AND "store"=?
95 ]]; 94 ]];
96 engine:delete(delete_sql, host, user or "", store); 95 engine:delete(delete_sql, host, user or "", store);
121 --- Key/value store API (default store type) 120 --- Key/value store API (default store type)
122 121
123 local keyval_store = {}; 122 local keyval_store = {};
124 keyval_store.__index = keyval_store; 123 keyval_store.__index = keyval_store;
125 function keyval_store:get(username) 124 function keyval_store:get(username)
126 user, store = username, self.store; 125 local ok, result = engine:transaction(keyval_store_get, username, self.store);
127 local ok, result = engine:transaction(keyval_store_get);
128 if not ok then 126 if not ok then
129 module:log("error", "Unable to read from database %s store for %s: %s", store, username or "<host>", result); 127 module:log("error", "Unable to read from database %s store for %s: %s", self.store, username or "<host>", result);
130 return nil, result; 128 return nil, result;
131 end 129 end
132 return result; 130 return result;
133 end 131 end
134 function keyval_store:set(username, data) 132 function keyval_store:set(username, data)
135 user,store = username,self.store; 133 return engine:transaction(keyval_store_set, data, username, self.store);
136 return engine:transaction(function()
137 return keyval_store_set(data);
138 end);
139 end 134 end
140 function keyval_store:users() 135 function keyval_store:users()
141 local ok, result = engine:transaction(function() 136 local ok, result = engine:transaction(function()
142 local select_sql = [[ 137 local select_sql = [[
143 SELECT DISTINCT "user" 138 SELECT DISTINCT "user"