Comparison

plugins/mod_storage_sql.lua @ 5035:874cab7b4b3e

mod_storage_sql: Add method for listing stores
author Kim Alvefur <zash@zash.se>
date Sat, 28 Jul 2012 21:27:45 +0200
parent 5034:2dbb3bf74090
child 5040:685403a6fee1
comparison
equal deleted inserted replaced
5034:2dbb3bf74090 5035:874cab7b4b3e
350 return setmetatable({ store = store }, keyval_store); 350 return setmetatable({ store = store }, keyval_store);
351 end 351 end
352 return nil, "unsupported-store"; 352 return nil, "unsupported-store";
353 end 353 end
354 354
355 function driver:list_stores(username) -- Not to be confused with the list store type
356 local sql = (username == true
357 and "SELECT DISTINCT `store` FROM `prosody` WHERE `host`=? AND `user`!=?"
358 or "SELECT DISTINCT `store` FROM `prosody` WHERE `host`=? AND `user`=?");
359 if username == true or not username then
360 username = "";
361 end
362 local stmt, err = dosql(sql, host, username);
363 if not stmt then
364 return nil, err;
365 end
366 local stores = {};
367 for row in stmt:rows() do
368 stores[#stores+1] = row[1];
369 end
370 return stores;
371 end
372
355 module:add_item("data-driver", driver); 373 module:add_item("data-driver", driver);