Diff

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
line wrap: on
line diff
--- a/plugins/mod_storage_sql.lua	Fri Sep 21 17:23:08 2012 +0200
+++ b/plugins/mod_storage_sql.lua	Fri Sep 21 17:24:06 2012 +0200
@@ -298,6 +298,17 @@
 	end
 	if success then return ret, err; else return rollback(nil, ret); end
 end
+function keyval_store:users()
+	local stmt, err = dosql("SELECT DISTINCT `user` FROM `prosody` WHERE `host`=? AND `store`=?", host, self.store);
+	if not stmt then
+		return rollback(nil, err);
+	end
+	local next = stmt:rows();
+	return commit(function()
+		local row = next();
+		return row and row[1];
+	end);
+end
 
 local function map_store_get(key)
 	local stmt, err = getsql("SELECT * FROM `prosody` WHERE `host`=? AND `user`=? AND `store`=? AND `key`=?", key or "");