Module:CargoUtil

local MAX_ROWS_IN_RESULT = 5000

local p = {} local h = {}

function p.query(query) local copyQuery = h.cloneAndCastQuery(query) local result = h.doQuery(copyQuery) local extraResult = result while copyQuery.continue and #extraResult == MAX_ROWS_IN_RESULT do		copyQuery.offset = (copyQuery.offset or 0) + MAX_ROWS_IN_RESULT extraResult = h.doQuery(copyQuery) for _, row in ipairs(extraResult) do			result[#result+1] = row end end return result end

function h.cloneAndCastQuery(query) local copyQuery = mw.clone(query) if query.continue then copyQuery.limit = MAX_ROWS_IN_RESULT end return copyQuery end

function h.doQuery(query) return mw.ext.cargo.query(		query.tables,		query.fields,		query	) end

return p