Changeset

5848:06156bfd4eaf

mod_storage_sql2: Add method for deleting items from archives with same syntax as :find()
author Kim Alvefur <zash@zash.se>
date Sat, 28 Sep 2013 22:04:04 +0200
parents 5847:6aaa7ad4463c
children 5850:e8c743f4213f
files plugins/mod_storage_sql2.lua
diffstat 1 files changed, 15 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_storage_sql2.lua	Sat Sep 28 21:58:01 2013 +0200
+++ b/plugins/mod_storage_sql2.lua	Sat Sep 28 22:04:04 2013 +0200
@@ -340,6 +340,21 @@
 	end, total;
 end
 
+function archive_store:delete(username, query)
+	query = query or {};
+	local user,store = username,self.store;
+	return engine:transaction(function()
+		local sql_query = "DELETE FROM `prosodyarchive` WHERE %s;";
+		local args = { host, user or "", store, };
+		local where = { "`host` = ?", "`user` = ?", "`store` = ?", };
+		archive_where(query, args, where);
+		archive_where_id_range(query, args, where);
+		sql_query = sql_query:format(t_concat(where, " AND "));
+		module:log("debug", sql_query);
+		return engine:delete(sql_query, unpack(args));
+	end);
+end
+
 local stores = {
 	keyval = keyval_store;
 	archive = archive_store;