mirror of
https://github.com/lxsang/silk.git
synced 2024-12-25 04:28:21 +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)
|
||||
end
|
||||
|
||||
if self.limit then
|
||||
table.insert(segments, "LIMIT "..self.limit)
|
||||
end
|
||||
|
||||
return true, table.concat(segments, " ")
|
||||
end
|
||||
|
||||
@ -161,7 +165,13 @@ function SQLQueryGenerator:sql_where(cond, obj)
|
||||
if k == "$and" or k == "$or" then
|
||||
table.insert(conds, self:sql_where(k, v))
|
||||
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
|
||||
|
||||
@ -170,7 +180,7 @@ end
|
||||
|
||||
function SQLQueryGenerator:parse_value(v, types)
|
||||
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
|
||||
if type(v) == "number" then
|
||||
return tostring(v)
|
||||
|
@ -401,6 +401,7 @@ test("SQL Generator", function()
|
||||
user = "dany'",
|
||||
["$or"] = {
|
||||
email = "test@mail.com",
|
||||
age = {10,20,30,40},
|
||||
["age$ne"] = 30,
|
||||
["$and"] = {
|
||||
["birth$ne"] = 1986,
|
||||
|
Loading…
Reference in New Issue
Block a user