Module:Cargo
Aller à la navigation
Aller à la recherche
La documentation pour ce module peut être créée à Module:Cargo/doc
local p = {}
local cargo = mw.ext.cargo
local w_frame = require( 'module:frame' )
local tableau = require( 'module:tableau' )
local w_table = require( 'module:tableau' )
function p.requete( f )
local args = tableau.toutRogner( tableau.obtenirArgs( f ) )
local resultatsRequete = cargo.query( args.tables, args.champs or '', {
join = args['joindre avec'],
where = args['où'],
groupBy = args['grouper par'],
having = args['ayant'],
orderBy = args['trier_par'] or args['trier par'],
limit = args.limite,
offset = args['décalage']
} )
local resultatParse = ''
for _, element in pairs( resultatsRequete ) do
resultatParse = resultatParse .. mw.getCurrentFrame():expandTemplate{
title = args["modèle"],
args = tableau.igsub( element, '_', ' ' )
}
end
return resultatParse
end
function p.query( f )
local args = w_frame.args( f )
local query_result = cargo.query( args.tables or '', args.fields or '_pageName', {
join = args['join on'],
where = args.where,
groupBy = args['group by'],
having = args.having,
orderBy = args['order by'] or '_pageName ASC',
limit = args.limit,
offset = args.offset
} )
if #query_result == 0 then
return args.default
end
if args['unique on'] then
query_result = w_table.unique( query_result, args['unique on'] )
end
local parsed_result = {}
if args.template then
local frame = mw.getCurrentFrame()
for index, element in ipairs( query_result ) do
parsed_result[index] = frame:expandTemplate{
title = args.template,
args = w_table.igsub( element, '_', ' ' )
}
end
else
for index, element in ipairs( query_result ) do
for _, value in pairs( element ) do
parsed_result[index] = value
break
end
end
end
return ( args.intro or '' ) .. table.concat( parsed_result, args.delimiter or '' ) .. ( args.outro or '' )
end
return p