Changeset

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
parents 5034:2dbb3bf74090
children 5036:be33164aa97e
files plugins/mod_storage_sql.lua
diffstat 1 files changed, 18 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_storage_sql.lua	Sat Jul 28 21:26:33 2012 +0200
+++ b/plugins/mod_storage_sql.lua	Sat Jul 28 21:27:45 2012 +0200
@@ -352,4 +352,22 @@
 	return nil, "unsupported-store";
 end
 
+function driver:list_stores(username) -- Not to be confused with the list store type
+	local sql = (username == true
+		and "SELECT DISTINCT `store` FROM `prosody` WHERE `host`=? AND `user`!=?"
+		or  "SELECT DISTINCT `store` FROM `prosody` WHERE `host`=? AND `user`=?");
+	if username == true or not username then
+		username = "";
+	end
+	local stmt, err = dosql(sql, host, username);
+	if not stmt then
+		return nil, err;
+	end
+	local stores = {};
+	for row in stmt:rows() do
+		stores[#stores+1] = row[1];
+	end
+	return stores;
+end
+
 module:add_item("data-driver", driver);