Module:CargoUtil

-- CargoUtil local p = {}

-- modifies a pre-existing query to add an extra set of conditions to get the max/min value of some field -- order will be either MIN or MAX, and orderby is usually going to be a date/datetime -- example: c.makeMinMaxQuery(cargoquery, 'SP.Champion','SP.Time','MAX') --to get the most-recent played champions function p.makeMinMaxQuery(cargoquery, field, orderby, order) result = mw.ext.cargo.query(cargoquery.tables,		string.format("%s(%s)=thisvalue, %s=thisfield", order, orderby, field ),		cargoquery) local newcondition = {} for _, row in ipairs(result) do		newcondition[#newcondition+1] = string.format(			'(%s="%s" AND %s="%s")',			field,			row.thisfield,			orderby,			row.thisvalue		) end local newwhere = { string.format("(%s)",table.concat(newcondition, ' OR ')), }	if cargoquery.where and cargoquery.where ~= '' then newwhere[2] = string.format("(%s)",cargoquery.where) end local cargowhere = table.concat(newwhere, ' AND ') return cargowhere end

function p.getOneResult(tbl, field, query) local result = mw.ext.cargo.query(tbl, field, query) if result[1] then if result[1][field] == '' then return nil else return result[1][field] end else return nil end end

return p