1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
local model = require "orbit.model"
local function build_query(sql, values)
return model.condition_parser:match(sql, 1, function (field, op)
return field .. op .. values[field]
end)
end
local queries = {
{
from = [[node_term.term = term.id and term.vocabulary = vocabulary.id and term.name = ? and
vocabulary.name = ?]],
to = [[node_term.term = term.id and term.vocabulary = vocabulary.id and term.name = visibility and vocabulary.name = home]],
values = { ["vocabulary.name"] = "home", ["term.name"] = "visibility" }
},
{
from = [[node_term.term = term.id and term.vocabulary = vocabulary.id and term.name = ? and
vocabulary.name = ? and term.display_name is not null]],
to = [[node_term.term = term.id and term.vocabulary = vocabulary.id and term.name = visibility and vocabulary.name = home and term.display_name is not null]],
values = { ["vocabulary.name"] = "home", ["term.name"] = "visibility" }
},
{
from = [[node in ?]],
to = [[node in foo]],
values = { node = "foo" }
},
{
from = [[node_term.term!=term and term.vocabulary = vocabulary.id and term.name = ? and
vocabulary.name = ? and term.display_name is not null]],
to = [[node_term.term!=term and term.vocabulary = vocabulary.id and term.name = visibility and vocabulary.name = home and term.display_name is not null]],
values = { ["vocabulary.name"] = "home", ["term.name"] = "visibility" }
},
{
from = [[node_term.term!=term and term.vocabulary = vocabulary.id and term.name =? and
vocabulary.name = ? and term.display_name is not null]],
to = [[node_term.term!=term and term.vocabulary = vocabulary.id and term.name =visibility and vocabulary.name = home and term.display_name is not null]],
values = { ["vocabulary.name"] = "home", ["term.name"] = "visibility" }
},
}
for _, q in ipairs(queries) do
if not (build_query(q.from, q.values) == q.to) then
print(build_query(q.from, q.values))
end
end
|