mirror of
https://github.com/lxsang/silk.git
synced 2024-11-16 02:08:22 +01:00
Allow to declare multiple ORs of the same field in the SQL filter object
All checks were successful
gitea-sync/silk/pipeline/head This commit looks good
All checks were successful
gitea-sync/silk/pipeline/head This commit looks good
This commit is contained in:
parent
efe5281f2f
commit
71434c48ff
@ -60,6 +60,10 @@ function SQLQueryGenerator:sql_select()
|
|||||||
table.insert(segments, o)
|
table.insert(segments, o)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if self.limit then
|
||||||
|
table.insert(segments, "LIMIT "..self.limit)
|
||||||
|
end
|
||||||
|
|
||||||
return true, table.concat(segments, " ")
|
return true, table.concat(segments, " ")
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -161,7 +165,13 @@ function SQLQueryGenerator:sql_where(cond, obj)
|
|||||||
if k == "$and" or k == "$or" then
|
if k == "$and" or k == "$or" then
|
||||||
table.insert(conds, self:sql_where(k, v))
|
table.insert(conds, self:sql_where(k, v))
|
||||||
else
|
else
|
||||||
table.insert(conds, self:binary(k, v))
|
if type(v) == "table" and not (k:match("%$.*in") or k:match("%$.*between") ) then
|
||||||
|
for i,el in ipairs(v) do
|
||||||
|
table.insert(conds, self:binary(k, el))
|
||||||
|
end
|
||||||
|
else
|
||||||
|
table.insert(conds, self:binary(k, v))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -170,7 +180,7 @@ end
|
|||||||
|
|
||||||
function SQLQueryGenerator:parse_value(v, types)
|
function SQLQueryGenerator:parse_value(v, types)
|
||||||
if not types[type(v)] then
|
if not types[type(v)] then
|
||||||
self:error("Type error: unexpected type %d", type(v))
|
self:error("Type error: unexpected type %s", type(v))
|
||||||
end
|
end
|
||||||
if type(v) == "number" then
|
if type(v) == "number" then
|
||||||
return tostring(v)
|
return tostring(v)
|
||||||
|
@ -401,6 +401,7 @@ test("SQL Generator", function()
|
|||||||
user = "dany'",
|
user = "dany'",
|
||||||
["$or"] = {
|
["$or"] = {
|
||||||
email = "test@mail.com",
|
email = "test@mail.com",
|
||||||
|
age = {10,20,30,40},
|
||||||
["age$ne"] = 30,
|
["age$ne"] = 30,
|
||||||
["$and"] = {
|
["$and"] = {
|
||||||
["birth$ne"] = 1986,
|
["birth$ne"] = 1986,
|
||||||
|
Loading…
Reference in New Issue
Block a user