Module:CargoQuery: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
|||
Line 12: | Line 12: | ||
local args = h.merge() | local args = h.merge() | ||
result = | local query = {} | ||
for k, v in pairs(args) do | |||
if string.sub(k, 0, 2) == 'q?' then | |||
local key = string.sub(k, 3) | |||
query[PARAM_LOOKUP[key] or key] = v | |||
elseif PARAM_LOOKUP[k] then | |||
query[PARAM_LOOKUP[k]] = v | |||
else | |||
query[k] = v | |||
end | |||
end | |||
if args.one_to_many then | |||
query.fields = query.fields .. ',' .. query.one_to_many | |||
end | |||
local result = mw.ext.cargo.query(query.tables, query.fields, query) | |||
if #result == 0 then | if #result == 0 then | ||
return frame:preprocess(args.default or '') | return frame:preprocess(args.default or '') | ||
end | end | ||
if args.one_to_many then | |||
result = h.groupOneToManyFields(result, h.getOneToManyTableFromArgs(args)) | |||
h.concatOneToManyFieldsInEachRow(result, args.one_to_many_sep or ',') | |||
end | |||
local tbl = {} | |||
for i, row in ipairs(result) do | for i, row in ipairs(result) do | ||
row.index = i | row.index = i |