Binding of Isaac: Rebirth Wiki
No edit summary
No edit summary
Line 27: Line 27:
 
elseif format == "list" then
 
elseif format == "list" then
 
for _, element in ipairs( query_result ) do
 
for _, element in ipairs( query_result ) do
parsed_result = parsed_result .. ';' .. element[1]
+
parsed_result = parsed_result .. ';' .. element["aaa"]
 
end
 
end
 
parsed_result = parsed_result:sub( 1 )
 
parsed_result = parsed_result:sub( 1 )

Revision as of 20:48, 26 August 2019

Template-info Documentation

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 of No 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 like template if the template parameter is used and like list otherwise.
  • named args can not be used, all arguments are always named.
Additional module parameters
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

local p = {}

local cargo  = mw.ext.cargo
local rtable = require( 'module:table' )

function p.query( f )
    local args         = rtable.trimAll( f.args )
    local query_result = 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'] or '_ID',
        limit   = args.limit,
        offset  = args.offset
    } )
    local parsed_result = ''

    local format = args.format or #query_result > 1 and "table" or "list"
    if format == "template" then 
        for _, element in ipairs( query_result ) do
            parsed_result = parsed_result .. mw.getCurrentFrame():expandTemplate{
                title = args.template,
                args  = rtable.igsub( element, '_', ' ' )
            }
        end
    elseif format == "list" then
        for _, element in ipairs( query_result ) do
            parsed_result = parsed_result .. ';' .. element["aaa"]
        end
        parsed_result = parsed_result:sub( 1 )
    else
        parsed_result = '<span style="color: red">[format not yet coded, sorry…]</span>'
    end

    return parsed_result
end

return p