Comparison

plugins/mod_storage_sql2.lua @ 6737:9f932a31eeba

mod_storage_sql2: Some reformatting and variable name improvements
author Matthew Wild <mwild1@gmail.com>
date Wed, 24 Jun 2015 22:55:41 +0100
parent 6736:4aee55c0cc5c
child 6738:845bc5ba306d
comparison
equal deleted inserted replaced
6736:4aee55c0cc5c 6737:9f932a31eeba
195 --- Key/value store API (default store type) 195 --- Key/value store API (default store type)
196 196
197 local keyval_store = {}; 197 local keyval_store = {};
198 keyval_store.__index = keyval_store; 198 keyval_store.__index = keyval_store;
199 function keyval_store:get(username) 199 function keyval_store:get(username)
200 user,store = username,self.store; 200 user, store = username, self.store;
201 local ok, result = engine:transaction(keyval_store_get); 201 local ok, result = engine:transaction(keyval_store_get);
202 if not ok then return ok, result; end 202 if not ok then return ok, result; end
203 return result; 203 return result;
204 end 204 end
205 function keyval_store:set(username, data) 205 function keyval_store:set(username, data)
359 end 359 end
360 return nil, "unsupported-store"; 360 return nil, "unsupported-store";
361 end 361 end
362 362
363 function driver:stores(username) 363 function driver:stores(username)
364 local sql = "SELECT DISTINCT `store` FROM `prosody` WHERE `host`=? AND `user`" .. 364 local query = "SELECT DISTINCT `store` FROM `prosody` WHERE `host`=? AND `user`" ..
365 (username == true and "!=?" or "=?"); 365 (username == true and "!=?" or "=?");
366 if username == true or not username then 366 if username == true or not username then
367 username = ""; 367 username = "";
368 end 368 end
369 local ok, result = engine:transaction(function() 369 local ok, result = engine:transaction(function()
370 return engine:select(sql, host, username); 370 return engine:select(query, host, username);
371 end); 371 end);
372 if not ok then return ok, result end 372 if not ok then return ok, result end
373 return iterator(result); 373 return iterator(result);
374 end 374 end
375 375
376 function driver:purge(username) 376 function driver:purge(username)
377 return engine:transaction(function() 377 return engine:transaction(function()
378 local stmt,err = engine:delete("DELETE FROM `prosody` WHERE `host`=? AND `user`=?", host, username); 378 local stmt,err = engine:delete("DELETE FROM `prosody` WHERE `host`=? AND `user`=?", host, username);
379 return true,err; 379 return true, err;
380 end); 380 end);
381 end 381 end
382 382
383 module:provides("storage", driver); 383 module:provides("storage", driver);
384 384