Software /
code /
prosody
Comparison
plugins/mod_storage_sql.lua @ 5130:051d352ed03c
storagemanager, datamanager, mod_storage_{internal,sql}: Replace list_stores() with an iterator version
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 17 Sep 2012 05:42:10 +0200 |
parent | 5056:a125daa42ad4 |
child | 5132:ce6546f867f9 |
comparison
equal
deleted
inserted
replaced
5129:e8253c931166 | 5130:051d352ed03c |
---|---|
372 return setmetatable({ store = store }, keyval_store); | 372 return setmetatable({ store = store }, keyval_store); |
373 end | 373 end |
374 return nil, "unsupported-store"; | 374 return nil, "unsupported-store"; |
375 end | 375 end |
376 | 376 |
377 function driver:list_stores(username) -- Not to be confused with the list store type | 377 function driver:stores(username) -- Not to be confused with the list store type |
378 local sql = (username == true | 378 local sql = "SELECT DISTINCT `store` FROM `prosody` WHERE `host`=? AND `user`" .. |
379 and "SELECT DISTINCT `store` FROM `prosody` WHERE `host`=? AND `user`!=?" | 379 (username == true and "!=?" or "=?"); |
380 or "SELECT DISTINCT `store` FROM `prosody` WHERE `host`=? AND `user`=?"); | |
381 if username == true or not username then | 380 if username == true or not username then |
382 username = ""; | 381 username = ""; |
383 end | 382 end |
384 local stmt, err = dosql(sql, host, username); | 383 local stmt, err = dosql(sql, host, username); |
385 if not stmt then | 384 if not stmt then |
386 return rollback(nil, err); | 385 return rollback(nil, err); |
387 end | 386 end |
388 local stores = {}; | 387 local next = stmt:rows(); |
389 for row in stmt:rows() do | 388 return commit(function() |
390 stores[#stores+1] = row[1]; | 389 local row = next(); |
391 end | 390 return row and row[1]; |
392 return commit(stores); | 391 end); |
393 end | 392 end |
394 | 393 |
395 function driver:purge(username) | 394 function driver:purge(username) |
396 local stmt, err = dosql("DELETE FROM `prosody` WHERE `host`=? AND `user`=?", host, username); | 395 local stmt, err = dosql("DELETE FROM `prosody` WHERE `host`=? AND `user`=?", host, username); |
397 if not stmt then return rollback(stmt, err); end | 396 if not stmt then return rollback(stmt, err); end |