Module:CargoQuery/doc: Difference between revisions

From Caves of Qud Wiki
Jump to navigation Jump to search
m (add module category)
(update for to most recent)
Line 1: Line 1:
This module is taken from [https://help.gamepedia.com/Module:CargoQuery Gamepedia's CargoQuery module].
This module is taken from [https://lol.gamepedia.com/Module:CargoQuery Leaguepedia's CargoQuery module].


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. 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.)


To use, preface query arguments with <code>q?</code>. Even if you are only using one table, use <code>|q?tables=</code>.
Unlike <code>|format=template</code>, this wrapper will NOT rename parameters with underscores in them to use spaces instead.
You must specify the template that will handle each row of the query result using <code>|template=</code>.
== Parameters ==
You may additionally specify <code>|intro=</code>, <code>|outro=</code>, <code>|delimiter=</code>, and <code>|default=</code>.
* 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.
 
For simplicity of code, the named args parameter is required to be Yes, and you do not need to specify it.


Unlike <code>|format=template</code>, this wrapper will NOT rename parameters with underscores in them to use spaces instead.
== One-To-Many ==
==Parameters & Invocation==
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:
<pre>{{#invoke:CargoQuery|main
* <code>|one_to_many=</code>, a list of fields you want concatenated together.
|q?tables= <!-- corresponds to table / tables -->
* <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.
|q?join= <!-- corresponds to join on -->
* <code>|one_to_many_sep=</code>, defaults to comma. Currently you must pick the same separator for ''all'' of your one-to-many fields.
|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=      <!-- pagename of template (required) -->
|intro=
|outro=
|delimiter=
|default=
}}</pre>


=== Example ===
<pre>
{{#invoke:CargoQuery|main
|table=Teams,ListplayerCurrent=LPC
|join on=Teams._pageName=LPC._pageName
|where=Teams.Region="North America" AND LPC._pageName IS NOT NULL
|fields=Teams._pageName=Page
|one_to_many=LPC.ID=IDs
|one_to_many_group=Page
|one_to_many_sep=,
|template=<template>
|intro={{(!}} class="wikitable"
|outro={{!)}}
|limit=10
}}
</pre>
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.
<includeonly>
<includeonly>
[[Category:Modules]]
[[Category:Modules]]
</includeonly>
</includeonly>

Revision as of 22:54, 6 March 2020

This module is taken from Leaguepedia's CargoQuery module.

This module lets you get around the |no html bug that Cargo has by avoiding |format=template. This module implicitly assumed you ARE using named args in your template (corresponding to |named_args=yes; you do not need to specify this.)

Unlike |format=template, this wrapper will NOT rename parameters with underscores in them to use spaces instead.

Parameters

  • You may specify all parameters the same as if they were parameters in #cargo_query.

One-To-Many

This template allows for one-to-many support, allowing you to specify a field to treat equivalently to a List of ... field. Syntax is as follows:

  • |one_to_many=, a list of fields you want concatenated together.
  • |one_to_many_group=, the thing you want our one-to-many values grouped by. UNLIKE the |group by= parameter, this should be the FINAL name of a field, so something on the RIGHT SIDE of the equals sign in your |fields= parameter.
  • |one_to_many_sep=, defaults to comma. Currently you must pick the same separator for all of your one-to-many fields.

Example

{{#invoke:CargoQuery|main
 |table=Teams,ListplayerCurrent=LPC
 |join on=Teams._pageName=LPC._pageName
 |where=Teams.Region="North America" AND LPC._pageName IS NOT NULL
 |fields=Teams._pageName=Page
 |one_to_many=LPC.ID=IDs
 |one_to_many_group=Page
 |one_to_many_sep=,
 |template=<template>
 |intro={{(!}} class="wikitable"
 |outro={{!)}}
 |limit=10
}}

Here, the one_to_many is a list of players on the team in question. For each ONE team, there are MANY players, so the field IDs that's sent to the template is a comma-separated list of players, grouped by team page.