Module:Sequences

local p = {} local h = {}

local utilsCargo = require('Module:UtilsCargo')

local cargoTable = "UniverseOrder" -- "Order" can't be used because it's an SQL keyword

function p.CargoDeclare(frame) return utilsCargo.declare(cargoTable, {		media = "String",		universeOrder = "String",		name = "String",		ordinal = "Integer",	}) end

function p.CargoStore(frame) local args = frame:getParent.args return h.store({		media = args[1],		order = args[2],		names = utilsTable.slice(3)(args),	}) end

-- @return a function that sorts @names according to the given @order for the given @media defined at `Data:Order` -- function p.sort(media, order) -- 	-- @return sorted names, minus those that were not defined for the given sort order -- 	-- @return names not defined for the given sort order -- 	return function(names) -- 		local queryResults = utilsCargo.query(cargoTable, { -- 			where= ("Media='%s' AND Order='%s'"):format(media, order), -- 			orderBy= "Ordinal", -- 		}) -- 		local indexes = utilsTable.groupBy("Ordinal", queryResults) -- 		local unsorted, toSort = utilsTable.partition -- 		local sorted = {} -- 		for _, queryResult in ipairs(queryResults) do -- 			local originalKey = hash[queryResult["Term"]] -- 			if originalKey then -- 				table.insert(sortedValues, valuesToSort[originalKey]) -- 				valuesToSort[originalKey] = nil -- 			end -- 		end -- 		return sortedValues, valuesToSort -- 		end -- end

function h.store(args) local validator = utilsArg.validator({		media = { nonEmpty = true },		order = { nonEmpty = true },		names = { nonEmpty = true },	}) local err = validator(args) if err then return utilsMarkup.categories(err) end for i, v in ipairs(args.terms) do		utilsCargo.store(cargoTable, {			media = args.game,			universeOrder = args.order,			ordinal = i,			name = v,		}) end end

return p