X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=plugins%2Fmod_storage_sql.lua;h=f6fa94e700930cb9e87536c0b6507c548cd4001b;hb=d631eea82c5144b9c2142b32affdb0ba4f878a43;hp=c20e4473a47b9c0e35123a3e4577bd6a7e00439c;hpb=e358ec18ba4a5385d20691cb5455c54bf9f18b78;p=prosody.git diff --git a/plugins/mod_storage_sql.lua b/plugins/mod_storage_sql.lua index c20e4473..f6fa94e7 100644 --- a/plugins/mod_storage_sql.lua +++ b/plugins/mod_storage_sql.lua @@ -79,8 +79,8 @@ local function connect() connection = dbh; connections[dburi] = dbh; - return connection; end + return connection; end local function create_table() @@ -298,6 +298,17 @@ function keyval_store:set(username, data) 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 ""); @@ -365,7 +376,7 @@ function list_store:scan(username, from, to, jid, typ) return nil, "not-implemented" end -local driver = { name = "sql" }; +local driver = {}; function driver:open(store, typ) if not typ then -- default key-value store @@ -374,10 +385,9 @@ function driver:open(store, typ) 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`=?"); +function driver:stores(username) + local sql = "SELECT DISTINCT `store` FROM `prosody` WHERE `host`=? AND `user`" .. + (username == true and "!=?" or "=?"); if username == true or not username then username = ""; end @@ -385,11 +395,11 @@ function driver:list_stores(username) -- Not to be confused with the list store if not stmt then return rollback(nil, err); end - local stores = {}; - for row in stmt:rows() do - stores[#stores+1] = row[1]; - end - return commit(stores); + local next = stmt:rows(); + return commit(function() + local row = next(); + return row and row[1]; + end); end function driver:purge(username) @@ -400,4 +410,4 @@ function driver:purge(username) return commit(true, changed); end -module:add_item("data-driver", driver); +module:provides("storage", driver);