Hearthstone Wiki

Hearthstone Wiki's database has been fully updated to Patch!


Hearthstone Wiki

The query function of this module is an alternative to #cargo_query with format=template. It should not be used as an alternative to #cargo_query for any other format.

The latter is subject to an intermittent bug that causes output to appear as unrendered HTML requiring a purge to correct. The query function avoids the bug by processing the template transclusion in Lua after running the query through Cargo, rather than having Cargo perform both steps.

Usage is similar to a #cargo_query call:


See Extension:Cargo/Querying data for more information, as the parameters here have the same usage as in #cargo_query with the following exceptions:

  • table cannot be used as an alternative to tables
  • join is used instead of join on
  • groupBy is used instead of group by
  • orderBy is used instead of order by
  • This function always behaves as if named args is yes

local p = {}

function p.makeError(msg)
	return tostring(
			:wikitext('Cargo Query Error: ', msg)
	) .. '[[Category:Pages with cargo query errors]]'

function p.query( frame )
    local success, results = pcall(mw.ext.cargo.query, frame.args.tables, frame.args.fields, {
        where = frame.args.where,
        join = frame.args.join,
        groupBy = frame.args.groupBy,
        having = frame.args.having,
        orderBy = frame.args.orderBy,
        limit = frame.args.limit,
        offset = frame.args.offset,
    } )
    if not success then 
    	return p.makeError(results)
    local out
    if #results > 0 then
    	out = frame.args.intro or ''
        for index = 1, #results, 1 do
            out = out .. '\n' .. frame:expandTemplate{ title = frame.args.template, args = results[index] }
    	out = out .. '\n' .. ( frame.args.outro or '' )
        out = frame.args.default or ''

    if frame.args.debug == "yes" then
        out = out .. "\n----\n" .. frame.args.where .. "\n----\nResults: " .. #results
    return out
return p