模块:Phrases/Query:修订间差异

来自「荏苒之境」
创建页面,内容为“local query = {} query.show = function(frame) end return query”
 
// via Wikitext Extension for VSCode
第1行: 第1行:
local translation = require("Module:Template translation")
local utils_str = require("Module:Utils/String")
local cargo = mw.ext.cargo
local escape_sql = utils_str.escape_sql
local query = {}
local query = {}
local function get(table_name, config)
    local theme_order_by = config.theme_order_by and escape_sql(config.theme_order_by)
    local phrase_order_by = config.phrase_order_by and escape_sql(config.phrase_order_by)
    local theme_limit = config.theme_limit
    local phrase_limit_per_theme = config.phrase_limit_per_theme
    local themes = cargo.query("PhraseThemes", "Theme", {
        where = "PhraseTable='"..table_name.."'",
        orderBy = theme_order_by,
        limit = theme_limit
    })
    local r = {}
    for _, theme in ipairs(themes) do
        local phrase_query = cargo.query(table_name, "Phrase", {
            where = "Theme='"..escape_sql(theme).."'",
            orderBy = phrase_order_by,
            limit = phrase_limit_per_theme,
        })
        local phrases = {}
        for _, entry in phrase_query do
            phrases[#phrases+1] = entry.Phrase
        end
        r[theme] = phrases
    end
    return r
end


query.show = function(frame)
query.show = function(frame)
    local args = frame.args
    local table_name = escape_sql(args.table)
    local parent_frame = frame:getParent()
local language = translation.getCurrentLanguageSubpage()
if language == nil or language == "" then
language = "zh-cn"
end
    local t = {"<ul>"}
    return table.concat(t)
end
end


return query
return query

2025年8月23日 (六) 20:31的版本

此模块的文档可以在模块:Phrases/Query/doc创建

local translation = require("Module:Template translation")
local utils_str = require("Module:Utils/String")

local cargo = mw.ext.cargo
local escape_sql = utils_str.escape_sql

local query = {}

local function get(table_name, config)
    local theme_order_by = config.theme_order_by and escape_sql(config.theme_order_by)
    local phrase_order_by = config.phrase_order_by and escape_sql(config.phrase_order_by)
    local theme_limit = config.theme_limit
    local phrase_limit_per_theme = config.phrase_limit_per_theme

    local themes = cargo.query("PhraseThemes", "Theme", {
        where = "PhraseTable='"..table_name.."'",
        orderBy = theme_order_by,
        limit = theme_limit
    })

    local r = {}
    for _, theme in ipairs(themes) do
        local phrase_query = cargo.query(table_name, "Phrase", {
            where = "Theme='"..escape_sql(theme).."'",
            orderBy = phrase_order_by,
            limit = phrase_limit_per_theme,
        })
        local phrases = {}
        for _, entry in phrase_query do
            phrases[#phrases+1] = entry.Phrase
        end
        r[theme] = phrases
    end
    return r
end

query.show = function(frame)
    local args = frame.args
    local table_name = escape_sql(args.table)

    local parent_frame = frame:getParent()
	local language = translation.getCurrentLanguageSubpage()
	if language == nil or language == "" then
		language = "zh-cn"
	end

    local t = {"<ul>"}


    return table.concat(t)
end

return query