Module:Songs: Difference between revisions

From Umamusume Wiki
Jump to navigation Jump to search
No edit summary
mNo edit summary
Line 55: Line 55:
local horseName = mw.text.decode(frame.args[1])
local horseName = mw.text.decode(frame.args[1])
if not horseName then return end
if not horseName then return end
local escaped = string.gsub(horseName, "'", "\\'")
-- local escaped = string.gsub(horseName, "'", "\\'")
local query = 'SELECT song_title, album FROM Album_Songs WHERE singers HOLDS "' .. escaped .. '"'
local query = 'SELECT song_title, album FROM Album_Songs WHERE singers HOLDS "' .. horseName .. '"'
local results = cargo.query(query)
local results = cargo.query(query)

Revision as of 18:11, 1 October 2024

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

local p = {}
local cargo = mw.ext.cargo

function p.albums(frame)
	local songName = mw.text.decode(frame.args[1])
	if not songName then return end
	local escaped = string.gsub(songName, "'", "\\'")
	local query = {
		join = "Album_Songs.album=Albums.title",
		where = "Album_Songs.song_page='" .. escaped .. "'",
		groupBy = "Albums.title",
		orderBy = "Albums.release_date ASC"
	}
	local fields = {
		'Albums._pageTitle=album_page',
		'Album_Songs.singers=singers'
	}
	local events = cargo.query('Albums, Album_Songs',
		table.concat(fields, ','), query)

	local text = ''
	for _, ev in ipairs(events) do
		text = text .. frame:expandTemplate{
			title='Song Albums/Entry',
			args=ev
		} .. '\n'
	end
	return text
end

function p.events(frame)
	local songName = mw.text.decode(frame.args[1])
	if not songName then return end
	local escaped = string.gsub(songName, "'", "\\'")
	local query = {
		join = "Setlist_Event._pageID=Setlist_Songs._pageID",
		where = "song_page='" .. escaped .. "'",
		orderBy = "event_order ASC, leg_order ASC, day ASC",
	}
	local fields = {'event_page', 'leg_name', 'day', 'cast'}
	local events = cargo.query('Setlist_Event, Setlist_Songs',
		table.concat(fields, ','), query)

	local text = ''
	for _, ev in ipairs(events) do
		text = text .. frame:expandTemplate{
			title='Song Events/Entry',
			args=ev
		} .. '\n'
	end
	return text
end

function p.songs(frame)
	local horseName = mw.text.decode(frame.args[1])
	if not horseName then return end
	-- local escaped = string.gsub(horseName, "'", "\\'")
	local query = 'SELECT song_title, album FROM Album_Songs WHERE singers HOLDS "' .. horseName .. '"'
	local results = cargo.query(query)
	
	local table = '{| class="wikitable sortable mw-collapsible"\n! Song !! Album\n'
	
	for _, row in ipairs(results) do
    	table = table .. '|-\n| ' .. row.song_title .. ' || ' .. row.album .. '\n'
	end

    table = table .. '|}'
    
    return table
end
return p