This module contains Cargo related functions.
query
Usage
{{#invoke: cargo | query
| tables =
| join on =
| fields =
| where =
| group by =
| having =
| order by =
| limit =
| offset =
| unique on =
| template =
| intro =
| outro =
| default =
}}
Description
An alternative to the {{#cargo_query: }}
parser function. Differences with the parser function:
default
defaults to an empty string instead ofNo results
.more results text
can not be used, this function does not add any link to additional results.no html
can not be used, as the formatting does not contain additional HTML.max display chars
can not be used, it could be added to this function if necessary.format
can not be used, this function works liketemplate
if thetemplate
parameter is used and likelist
otherwise.named args
can not be used, all arguments are always named.
Parameter | Description | Type | Status | |
---|---|---|---|---|
Unique on | unique on
|
Adds an extra filtering step on the result of the query, before calling the formatting template if any. Should be a column name from the output of the query. | String | optional |
The above documentation is transcluded from Module:Cargo/doc. (edit | history)
local p = {}
local cargo = mw.ext.cargo
local rtable = require( 'Module:Table' )
function p.query( f )
local args = rtable.trimAll( rtable.getArgs( f ) )
local queryResult = cargo.query( args.tables, args.fields or '', {
join = args['join on'],
where = args.where,
groupBy = args['group by'],
having = args.having,
orderBy = args['order by'],
limit = args.limit,
offset = args.offset
} )
local parsedResult = ''
for _, element in pairs( queryResult ) do
for param, value in pairs( rtable.gsub( element, '%s', ' ' ) ) do
parsedResult = parsedResult .. '"' .. param .. '"="' .. value .. '" '
end--[[mw.getCurrentFrame():expandTemplate{
title = args.template,
args = rtable.gsub( element, '_', ' ' )
}]]
end
return parsedResult
end
return p