Difference between revisions of "Module:CargoQuery/doc"

From Dragalia Lost Wiki
Jump to navigation Jump to search
>Eave
m (wrapping documentation in doc templates)
>Eave
(adding documentation for the new way to achieve the vardefine functionality)
 
(7 intermediate revisions by the same user not shown)
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 trick===
 +
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.
 +
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.
 +
 
== Dependencies ==
 
== Dependencies ==
 
* [[Module:ProcessArgs]]
 
* [[Module:ProcessArgs]]
 
{{doc/end}}
 
{{doc/end}}

Latest revision as of 04:53, 12 April 2020

50px Documentation

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 trick

There exists a Template:vardefine such that if it is passed in as the template 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. When using this template, the default template output is empty, however output-affecting parameters such as |intro=, |outro=, and |delimiter= will still be included in the return value. As usual, if no results are found, |default= will also still be used as the output, and no variables will be assigned.

Dependencies