RheingoldRiver (talk | contribs) No edit summary |
PhantomCaleb (talk | contribs) No edit summary |
||
Line 21: | Line 21: | ||
args = fields |
args = fields |
||
} |
} |
||
+ | end |
||
+ | |||
+ | function p.all(conditions) |
||
+ | if not conditions then |
||
+ | return nil |
||
+ | end |
||
+ | local where = nil |
||
+ | for _, condition in ipairs(conditions) do |
||
+ | local arg = condition[1] |
||
+ | local field = condition[2] |
||
+ | if arg and field and where then |
||
+ | where = string.format("%s AND %s=%s", where, field, arg) |
||
+ | elseif arg and field then |
||
+ | where = string.format("%s=%s", field, arg) |
||
+ | end |
||
+ | end |
||
+ | return where |
||
end |
end |
||
Revision as of 14:42, 24 February 2020
This module is a wrapper over mw.ext.cargo
. It also provides utilities for constructing queries.
Using this module instead of using mw.ext.cargo directly allows us to see via Special:WhatLinksHere what pages are running Cargo queries.
Lua error in Module:UtilsPage at line 14: attempt to call field 'allOf' (a nil value).
local p = {}
local cargo = mw.ext.cargo
local frame = mw.getCurrentFrame()
function p.declare(cargoTable, fields)
return frame:callParserFunction{
name = '#cargo_declare:_table=' .. cargoTable,
args = fields
}
end
function p.attach(cargoTable)
return frame:callParserFunction{
name = '#cargo_attach:' .. cargoTable
}
end
function p.store(cargoTable, fields)
frame:callParserFunction{
name = '#cargo_store:_table=' .. cargoTable,
args = fields
}
end
function p.all(conditions)
if not conditions then
return nil
end
local where = nil
for _, condition in ipairs(conditions) do
local arg = condition[1]
local field = condition[2]
if arg and field and where then
where = string.format("%s AND %s=%s", where, field, arg)
elseif arg and field then
where = string.format("%s=%s", field, arg)
end
end
return where
end
return setmetatable(p, {__index=cargo})