Module:UtilsCargo

local p = {} local cargo = mw.ext.cargo local utilsString = require("Module:UtilsString")

function p.Query(query) local queryFieldsTable = {} for key, field in ipairs(query["fields"]) do		table.insert(queryFieldsTable, field["name"]) end local queryFieldsString = table.concat(queryFieldsTable, ", ") local results = cargo.query(query["tables"], queryFieldsString, query["args"]) for key, field in ipairs(query["fields"]) do   	if field["type"] == "List  of String" then for key2, result in ipairs(results) do   			result[field["name"]] = utilsString.Explode(result[field["name"]], ",") end elseif field["type"] == "List of String" then for key2, result in ipairs(results) do   			result[field["name"]] = utilsString.Explode(result[field["name"]], ";") end elseif field["type"] == "Integer" then for key2, result in ipairs(results) do				result[field["name"]] = tonumber(result[field["name"]]) end elseif field["type"] == "Boolean" then for key2, result in ipairs(results) do				if result[field["name"]] == "1" then result[field["name"]] = true elseif result[field["name"]] == "0" then result[field["name"]] = false end end end end

return results end

return p