Software / code / prosody
Comparison
plugins/mod_storage_sql.lua @ 5154:429c8eeea035
mod_storage_sql: Add support for iterating over users with data in a store
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 21 Sep 2012 17:24:06 +0200 |
| parent | 5133:1443d1c37c6c |
| child | 5209:f5d121846d53 |
comparison
equal
deleted
inserted
replaced
| 5153:688aeac0012a | 5154:429c8eeea035 |
|---|---|
| 296 if not connection and connect() then | 296 if not connection and connect() then |
| 297 success, ret, err = xpcall(function() return keyval_store_set(data); end, debug.traceback); | 297 success, ret, err = xpcall(function() return keyval_store_set(data); end, debug.traceback); |
| 298 end | 298 end |
| 299 if success then return ret, err; else return rollback(nil, ret); end | 299 if success then return ret, err; else return rollback(nil, ret); end |
| 300 end | 300 end |
| 301 function keyval_store:users() | |
| 302 local stmt, err = dosql("SELECT DISTINCT `user` FROM `prosody` WHERE `host`=? AND `store`=?", host, self.store); | |
| 303 if not stmt then | |
| 304 return rollback(nil, err); | |
| 305 end | |
| 306 local next = stmt:rows(); | |
| 307 return commit(function() | |
| 308 local row = next(); | |
| 309 return row and row[1]; | |
| 310 end); | |
| 311 end | |
| 301 | 312 |
| 302 local function map_store_get(key) | 313 local function map_store_get(key) |
| 303 local stmt, err = getsql("SELECT * FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", key or ""); | 314 local stmt, err = getsql("SELECT * FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", key or ""); |
| 304 if not stmt then return rollback(nil, err); end | 315 if not stmt then return rollback(nil, err); end |
| 305 | 316 |