Latest revision |
Your text |
Line 1: |
Line 1: |
| {{doc/start}} | | {{doc/start}} |
| {{Copied
| | This module lets you get around the <code>|no html</code> bug that Cargo has by avoiding |format=template. |
| |page=https://lol.fandom.com/wiki/Module:CargoQuery
| |
| |site=https://lol.fandom.com
| |
| |sitename=League of Legends eSports Wiki
| |
| }}
| |
| This module lets you get around the <code>|no html</code> bug that Cargo has by avoiding |format=template. This module implicitly assumed you ARE using named args in your template (corresponding to <code>|named_args=yes</code>; you do not need to specify this.) | |
|
| |
|
| Unlike <code>|format=template</code>, this wrapper will NOT rename parameters with underscores in them to use spaces instead.
| | 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>. |
| == Parameters == | | |
| * You may specify all parameters the same as if they were parameters in <code>#cargo_query</code>.
| | Use Lua names of all query parameters, so <code>|q?join=</code>, <code>|q?groupBy</code>, etc. |
|
| |
|
| == One-To-Many ==
| | For simplicity of code, the named args parameter is required to be Yes, and you do not need to specify it. |
| This template allows for one-to-many support, allowing you to specify a field to treat equivalently to a <code>List of ...</code> field. Syntax is as follows:
| |
| * <code>|one_to_many=</code>, a list of fields you want concatenated together.
| |
| * <code>|one_to_many_group=</code>, the thing you want our one-to-many values grouped by. UNLIKE the <code>|group by=</code> parameter, this should be the FINAL name of a field, so something on the RIGHT SIDE of the equals sign in your <code>|fields=</code> parameter.
| |
| * <code>|one_to_many_sep=</code>, defaults to comma. Currently you must pick the same separator for ''all'' of your one-to-many fields.
| |
|
| |
|
| === Example === | | Unlike <code>|format=template</code>, this wrapper will NOT rename parameters with underscores in them to use spaces instead. |
| <pre> | | ==Parameters & Invocation== |
| {{#invoke:CargoQuery|main | | <pre>{{#invoke:CargoQuery|main |
| |table=Teams,ListplayerCurrent=LPC
| | |q?tables= corresponds to table / tables |
| |join on=Teams._pageName=LPC._pageName
| | |q?join= corresponds to join on |
| |where=Teams.Region="North America" AND LPC._pageName IS NOT NULL
| | |q?fields= corresponds to fields |
| |fields=Teams._pageName=Page
| | |q?where= corresponds to where |
| |one_to_many=LPC.ID=IDs
| | |q?groupBy= corresponds to group by |
| |one_to_many_group=Page
| | |q?having= corresponds to having |
| |one_to_many_sep=,
| | |q?orderBy= corresponds to order by |
| |template=<template>
| | |q?limit= corresponds to limit |
| |intro={{(!}} class="wikitable"
| | |template= |
| |outro={{!)}}
| | |intro= |
| |limit=10
| | |outro= |
| }} | | |delimiter= |
| </pre> | | |default= |
| Here, the <code>one_to_many</code> is a list of players on the team in question. For each ONE team, there are MANY players, so the field <code>IDs</code> that's sent to the template is a comma-separated list of players, grouped by team page.
| | }}</pre> |
|
| |
|
| == Compound Queries == | | ===vardefine trick=== |
| You can also run compound queries using <code>compound</code>. It has the same syntax as <code>#cargo_compound_query</code> but with a few exceptions:
| | There exists a [[Template:vardefine]] such that if it is passed in as the <code>template</code> parameter, the effect will be that every field's value is assigned to a variable named as the field name. '''Note:''' If multiple results are returned for a given query, due to the inherent behavior of #vardefine, the last result's values will override those of all the results that came before it. |
| * <code>default</code> for each individual query is disabled; default must be specified outside as an additional argument, which is then applied if no queries return results.
| | When using this template, the default template output is empty, however output-affecting parameters such as <code>|intro=</code>, <code>|outro=</code>, and <code>|delimiter=</code> will still be included in the return value. As usual, if no results are found, <code>|default=</code> will also still be used as the output, and no variables will be assigned. |
| * Each query must be numbered as in <code>|1=(query1)|2=(query2)|3=...</code>, etc.
| |
| * Because of how compound query uses <code>;</code> as a separator, strings with this character cannot be used. This can be worked around by specifying <code>metaseparator</code> to be another symbol, and splitting each query's arguments using that delimiter instead.
| |
|
| |
|
| === Example === | | == Dependencies == |
| <pre>
| | * [[Module:ProcessArgs]] |
| {{#invoke:CargoQuery|compound
| |
| |1=table=Food=F
| |
| ;fields=F._pageName=Page
| |
| ;where=F.CookEffect HOLDS 'heat and fire-based' AND F._pageNamespace = '0'
| |
| |2=table=Liquids=L
| |
| ;fields=L._pageName=Page
| |
| ;where=L.CookEffect HOLDS 'simple heat and fire-based' AND L._pageNamespace = '0'
| |
| |default=No Results!
| |
| |template=favilink page
| |
| |delimiter = <br>
| |
| |metaseparator = ;
| |
| }}
| |
| </pre>
| |
| {{doc/end}} | | {{doc/end}} |
| <includeonly>
| |
| [[Category:Helper modules]]
| |
| </includeonly>
| |