Jump to content

Module:ListPeople: Difference between revisions

From Benvenuti Music Library
No edit summary
No edit summary
 
Line 1: Line 1:
local p = {}
local p = {}
local cargo = mw.ext.cargo


function p.get()
function p.get()
    local cargo = mw.ext.cargo
     local peopleSet = {}
     local peopleSet = {}


     -- Fetch Composer values
     local function safeQuery(field)
    local composerResults = cargo.query('Compositions', 'Composer', {
        local success, result = pcall(function()
        groupBy = 'Composer',
            return cargo.query('Compositions', field, {
        limit = 1000
                groupBy = field,
    })
                limit = 1000
            })
        end)
        if not success then
            return {}
        end
        return result
    end


    -- Fetch Arranger values
     local function addNames(resultTable, field)
    local arrangerResults = cargo.query('Compositions', 'Arranger', {
        groupBy = 'Arranger',
        limit = 1000
    })
 
     local function addNames(resultTable)
         for _, row in ipairs(resultTable) do
         for _, row in ipairs(resultTable) do
             local fieldValue = row[1] or ''
             local names = row[field] or ''
             for name in mw.text.gsplit(fieldValue, '[,;]') do
             for name in mw.text.gsplit(names, '[,;]') do
                 name = mw.text.trim(name)
                 name = mw.text.trim(name)
                 if name ~= '' then
                 if name ~= '' then
Line 30: Line 30:
     end
     end


     addNames(composerResults)
    -- Query and process both Composer and Arranger
     addNames(arrangerResults)
    local composers = safeQuery('Composer')
     addNames(composers, 'Composer')
 
    local arrangers = safeQuery('Arranger')
     addNames(arrangers, 'Arranger')


     -- Convert to sorted list
     -- Sort and format
     local peopleList = {}
     local list = {}
     for name, _ in pairs(peopleSet) do
     for name in pairs(peopleSet) do
         table.insert(peopleList, name)
         table.insert(list, name)
     end
     end
     table.sort(peopleList)
     table.sort(list)


     -- Build output
     local output = {}
    local out = {}
     for _, name in ipairs(list) do
     for _, name in ipairs(peopleList) do
         table.insert(output, '* [[' .. name .. ']]')
         table.insert(out, '* [[' .. name .. ']]')
     end
     end


     return table.concat(out, '\n')
     return table.concat(output, '\n')
end
end


return p
return p

Latest revision as of 03:27, 23 July 2025

Documentation for this module may be created at Module:ListPeople/doc

local p = {}

function p.get()
    local cargo = mw.ext.cargo
    local peopleSet = {}

    local function safeQuery(field)
        local success, result = pcall(function()
            return cargo.query('Compositions', field, {
                groupBy = field,
                limit = 1000
            })
        end)
        if not success then
            return {}
        end
        return result
    end

    local function addNames(resultTable, field)
        for _, row in ipairs(resultTable) do
            local names = row[field] or ''
            for name in mw.text.gsplit(names, '[,;]') do
                name = mw.text.trim(name)
                if name ~= '' then
                    peopleSet[name] = true
                end
            end
        end
    end

    -- Query and process both Composer and Arranger
    local composers = safeQuery('Composer')
    addNames(composers, 'Composer')

    local arrangers = safeQuery('Arranger')
    addNames(arrangers, 'Arranger')

    -- Sort and format
    local list = {}
    for name in pairs(peopleSet) do
        table.insert(list, name)
    end
    table.sort(list)

    local output = {}
    for _, name in ipairs(list) do
        table.insert(output, '* [[' .. name .. ']]')
    end

    return table.concat(output, '\n')
end

return p