(Created page with "local p = {} local cargo = mw.ext.cargo function p.Main( frame ) local tables = 'Commendations' local fields = 'Commendation, COUNT(*)' -- optional parameters are grouped in one table -- you can omit any or all of them, except join if you use more than one table local args = { --where = '', --join = 'table1.fieldA = table2.fieldB,table2.fieldC=table3.fieldD, etc.', groupBy = 'Commendation', --having = 'table1.fieldG="s...") |
mNo edit summary |
||
Line 3: | Line 3: | ||
function p.Main( frame ) | function p.Main( frame ) | ||
local t = {} | |||
local tables = 'Commendations' | local tables = 'Commendations' | ||
local fields = 'Commendation, COUNT(*)' | local fields = 'Commendation, COUNT(*) AS cnt' | ||
-- optional parameters are grouped in one table | -- optional parameters are grouped in one table | ||
-- you can omit any or all of them, except join if you use more than one table | -- you can omit any or all of them, except join if you use more than one table | ||
Line 19: | Line 20: | ||
for r = 1, #results do | for r = 1, #results do | ||
local result = results[r] | local result = results[r] | ||
table.insert(t, result.Commendation .. " = " .. result.cnt) | |||
end | end | ||
return table.concat(t, '<br>') | |||
end | end | ||
return p | return p |
Revision as of 19:31, 8 November 2022
Documentation for this module may be created at Module:Commendations/doc
local p = {} local cargo = mw.ext.cargo function p.Main( frame ) local t = {} local tables = 'Commendations' local fields = 'Commendation, COUNT(*) AS cnt' -- optional parameters are grouped in one table -- you can omit any or all of them, except join if you use more than one table local args = { --where = '', --join = 'table1.fieldA = table2.fieldB,table2.fieldC=table3.fieldD, etc.', groupBy = 'Commendation', --having = 'table1.fieldG="some value", etc.', --orderBy = 'table2.fieldF, etc.', --limit = some number, --offset = some number, } local results = cargo.query( tables, fields, args ) for r = 1, #results do local result = results[r] table.insert(t, result.Commendation .. " = " .. result.cnt) end return table.concat(t, '<br>') end return p
Categories:
No categories