Difference between revisions of "Module:CargoQuery/doc"
>Eave m (wrapping documentation in doc templates) |
>Eave (adding documentation for vardefine mode) |
||
| Line 2: | Line 2: | ||
This module lets you get around the <code>|no html</code> bug that Cargo has by avoiding |format=template. | This module lets you get around the <code>|no html</code> bug that Cargo has by avoiding |format=template. | ||
| − | To use, preface query arguments with <code>q?</code>. Even if you are only using one table, use <code>|q?tables=</code>. You may additionally specify <code>|template=</code>, <code>|intro=</code>, <code>|outro=</code>, <code>|delimiter=</code>, and <code>|default=</code>. | + | To use, preface query arguments with <code>q?</code>. Even if you are only using one table, use <code>|q?tables=</code>. You may additionally specify <code>|template=</code> ('''required'''), <code>|intro=</code>, <code>|outro=</code>, <code>|delimiter=</code>, and <code>|default=</code>. |
Use Lua names of all query parameters, so <code>|q?join=</code>, <code>|q?groupBy</code>, etc. | Use Lua names of all query parameters, so <code>|q?join=</code>, <code>|q?groupBy</code>, etc. | ||
| Line 25: | Line 25: | ||
|default= | |default= | ||
}}</pre> | }}</pre> | ||
| + | |||
| + | ===vardefine mode=== | ||
| + | The <code>template</code> parameter can take a special value ''vardefine'', where instead of outputting a template output, it instead assigns every field's value to a variable named as the field name. In this mode, only the first result is honored, and the return-related parameters such as <code>|intro=</code>, <code>|outro=</code>, and <code>|delimiter=</code> will be ignored. The return value will be nil unless <code>|default=</code> is specified, which will still be used. For example the following are equivalent: | ||
| + | <pre> | ||
| + | {{#invoke:CargoQuery|main | ||
| + | |q?tables=Dragons | ||
| + | |q?where=FullName="Ariel" | ||
| + | |q?fields=ElementalType,Rarity,SkillName, | ||
| + | CONCAT('File:',BaseId, ' 0', VariationId, ' portrait.png')=Portrait,_pageName=Link | ||
| + | |?groupBy=_pageName | ||
| + | |template=vardefine | ||
| + | }} | ||
| + | </pre> | ||
| + | <pre> | ||
| + | {{#vardefine:ElementalType|Wind}} | ||
| + | {{#vardefine:Rarity|5}} | ||
| + | {{#vardefine:SkillName|Cyclone Kick}} | ||
| + | {{#vardefine:Portrait|File:210116 01 portrait.png}} | ||
| + | {{#vardefine:Link|Ariel}} | ||
| + | </pre> | ||
| + | |||
| + | '''Warning''': like all <code>{{#vardefine}}</code> calls, if you attempt to assign an identical field name a second time on the same page, it will overwrite the initial value. | ||
| + | |||
== Dependencies == | == Dependencies == | ||
* [[Module:ProcessArgs]] | * [[Module:ProcessArgs]] | ||
{{doc/end}} | {{doc/end}} | ||
Revision as of 03:34, 12 April 2020
This module lets you get around the |no html bug that Cargo has by avoiding |format=template.
To use, preface query arguments with q?. Even if you are only using one table, use |q?tables=. You may additionally specify |template= (required), |intro=, |outro=, |delimiter=, and |default=.
Use Lua names of all query parameters, so |q?join=, |q?groupBy, etc.
For simplicity of code, the named args parameter is required to be Yes, and you do not need to specify it.
Unlike |format=template, this wrapper will NOT rename parameters with underscores in them to use spaces instead.
Parameters & Invocation
{{#invoke:CargoQuery|main
|q?tables= corresponds to table / tables
|q?join= corresponds to join on
|q?fields= corresponds to fields
|q?where= corresponds to where
|q?groupBy= corresponds to group by
|q?having= corresponds to having
|q?orderBy= corresponds to order by
|q?limit= corresponds to limit
|template=
|intro=
|outro=
|delimiter=
|default=
}}
vardefine mode
The template parameter can take a special value vardefine, where instead of outputting a template output, it instead assigns every field's value to a variable named as the field name. In this mode, only the first result is honored, and the return-related parameters such as |intro=, |outro=, and |delimiter= will be ignored. The return value will be nil unless |default= is specified, which will still be used. For example the following are equivalent:
{{#invoke:CargoQuery|main
|q?tables=Dragons
|q?where=FullName="Ariel"
|q?fields=ElementalType,Rarity,SkillName,
CONCAT('File:',BaseId, ' 0', VariationId, ' portrait.png')=Portrait,_pageName=Link
|?groupBy=_pageName
|template=vardefine
}}
{{#vardefine:ElementalType|Wind}}
{{#vardefine:Rarity|5}}
{{#vardefine:SkillName|Cyclone Kick}}
{{#vardefine:Portrait|File:210116 01 portrait.png}}
{{#vardefine:Link|Ariel}}
Warning: like all {{#vardefine}} calls, if you attempt to assign an identical field name a second time on the same page, it will overwrite the initial value.