Changeset

8310:1759491b53db

mod_storage_internal: Add more extensive query support to archive:delete method
author Kim Alvefur <zash@zash.se>
date Mon, 09 Oct 2017 01:02:17 +0200
parents 8309:5281c479955a
children 8311:df8c82d285dc
files plugins/mod_storage_internal.lua
diffstat 1 files changed, 22 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_storage_internal.lua	Mon Oct 09 01:01:28 2017 +0200
+++ b/plugins/mod_storage_internal.lua	Mon Oct 09 01:02:17 2017 +0200
@@ -160,9 +160,6 @@
 	if not query or next(query) == nil then
 		return datamanager.list_store(username, host, self.store, nil);
 	end
-	for k in pairs(query) do
-		if k ~= "end" then return nil, "unsupported-query-field"; end
-	end
 	local items, err = datamanager.list_load(username, host, self.store);
 	if not items then
 		if err then
@@ -173,9 +170,28 @@
 	end
 	items = array(items);
 	local count_before = #items;
-	items:filter(function (item)
-		return item.when > query["end"];
-	end);
+	if query then
+		if query.key then
+			items:filter(function (item)
+				return item.key ~= query.key;
+			end);
+		end
+		if query.with then
+			items:filter(function (item)
+				return item.with ~= query.with;
+			end);
+		end
+		if query.start then
+			items:filter(function (item)
+				return item.when < query.start;
+			end);
+		end
+		if query["end"] then
+			items:filter(function (item)
+				return item.when > query["end"];
+			end);
+		end
+	end
 	local count = count_before - #items;
 	local ok, err = datamanager.list_store(username, host, self.store, items);
 	if not ok then return ok, err; end