# HG changeset patch
# User Kim Alvefur <zash@zash.se>
# Date 1610473577 -3600
# Node ID f225070e2b8ab8ead5040ecc81a76766e2b5b524
# Parent  c3907f05bed4b93b0be1a1db25bf841e7e78f843
mod_storage_sql: Support query for set of IDs

Not compatible with Lua 5.1

diff -r c3907f05bed4 -r f225070e2b8a plugins/mod_storage_sql.lua
--- a/plugins/mod_storage_sql.lua	Tue Jan 12 18:06:55 2021 +0100
+++ b/plugins/mod_storage_sql.lua	Tue Jan 12 18:46:17 2021 +0100
@@ -283,6 +283,7 @@
 	quota = archive_item_limit;
 	truncate = true;
 	full_id_range = true;
+	ids = true;
 };
 archive_store.__index = archive_store
 function archive_store:append(username, key, value, when, with)
@@ -376,6 +377,15 @@
 		where[#where+1] = "\"key\" = ?";
 		args[#args+1] = query.key
 	end
+
+	-- Set of ids
+	if query.ids then
+		local nids, nargs = #query.ids, #args;
+		where[#where + 1] = "\"key\" IN (" .. string.rep("?", nids, ",") .. ")";
+		for i, id in ipairs(query.ids) do
+			args[nargs+i] = id;
+		end
+	end
 end
 local function archive_where_id_range(query, args, where)
 	-- Before or after specific item, exclusive