Module:UtilsCargo

local p = {} local frame = mw.getCurrentFrame

function p.declare(cargoTable, fields) return frame:callParserFunction{ name = '#cargo_declare:_table=' .. cargoTable, args = fields } end

function p.store(cargoTable, fields) frame:callParserFunction{ name = '#cargo_store:_table=' .. cargoTable, args = fields } end

function p.query(tables, fields, args) return mw.ext.cargo.query(tables, fields, args) end

function p.allOf(conditions) local whereClause for k, v in pairs(conditions) do		v = string.gsub(v, "'", "\\'") if not whereClause then whereClause = string.format("%s='%s'", k, v)		else whereClause = string.format("%s AND %s='%s'", whereClause, k, v)		end end return whereClause end

p.Schemas = { declare = { tableName = { type = "string", required = true, },		fields = { type = "map", required = true, keys = { type = "string" }, values = { type = "string" }, },	},	store = { tableName = { type = "string", required = true, },		fields = { type = "map", required = true, keys = { type = "string" }, values = { type = "string" }, },	},	query = { tables = { type = "string", required = true, },		fields = { type = "string", required = true, },		args = { type = "record", properties = { {					name = "where", type = "string", },					{					name = "join", type = "string", },				{					name = "groupBy", type = "string", },				{					name = "having", type = "string", },				{					name = "orderBy", type = "string", },				{					name = "limit", type = "number", default = 100, },				{					name = "offset", type = "number", default = 0, },			}		},	},	allOf = { conditions = { type = "map", required = true, keys = { type = "string" }, values = { oneOf = {{ type = "string" }, { type = "number" }} }, },	} }

p.Documentation = { {		name = "declare", params = {"tableName", "fields"}, },	{		name = "store", params = {"tableName", "fields"}, },	{		name = "query", params = {"tables", "fields", "args"}, returns = "An array of the query results. Throws an error when query syntax is invalid.", cases = { {				args = { "Games", "initialism, subtitle", {						where = "type='main' AND mainrelease !=''", orderBy = "mainrelease", limit = 3, },				},				expected = { { initialism = "TLoZ", subtitle = "The Legend of Zelda"}, { initialism = "TAoL", subtitle = "The Adventure of Link"}, { initialism = "ALttP", subtitle = "A Link to the Past"}, },			},		}	},	{		name = "allOf", outputOnly = true, params = {"conditions"}, description = "Utility for constructing AND queries. Quotation marks are properly escaped.", cases = { {				args = { {						game = "Link's Awakening", remakeNum = 2, platform = "Nintendo Switch", },				},				expected = "game='Link\\'s Awakening' AND platform='Nintendo Switch' AND remakeNum='2'" }		},	} }

return p