Skip to content

Commit

Permalink
fix: or statements in brackets
Browse files Browse the repository at this point in the history
  • Loading branch information
artur-michalak committed Jun 18, 2024
1 parent 1db7c71 commit a71aaf8
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions server/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ local function buildWhereClause(filters)
end
local placeholders = {}
local whereClauseCrumbs = {}
if filters.vehicleId then
whereClauseCrumbs[#whereClauseCrumbs+1] = 'id = ?'
placeholders[#placeholders+1] = filters.vehicleId
end
if filters.citizenid then
whereClauseCrumbs[#whereClauseCrumbs+1] = 'citizenid = ?'
placeholders[#placeholders+1] = filters.citizenid
end
if filters.garage then
whereClauseCrumbs[#whereClauseCrumbs+1] = 'garage = ?'
placeholders[#placeholders+1] = filters.garage
end
if filters.states then
if type(filters.states) ~= 'table' then
---@diagnostic disable-next-line: assign-type-mismatch
Expand All @@ -68,21 +80,9 @@ local function buildWhereClause(filters)
placeholders[#placeholders+1] = filters.states[i]
statePlaceholders[i] = 'state = ?'
end
whereClauseCrumbs[#whereClauseCrumbs+1] = table.concat(statePlaceholders, ' OR ')
whereClauseCrumbs[#whereClauseCrumbs+1] = string.format('(%s)', table.concat(statePlaceholders, ' OR '))
end
end
if filters.vehicleId then
whereClauseCrumbs[#whereClauseCrumbs+1] = 'id = ?'
placeholders[#placeholders+1] = filters.vehicleId
end
if filters.citizenid then
whereClauseCrumbs[#whereClauseCrumbs+1] = 'citizenid = ?'
placeholders[#placeholders+1] = filters.citizenid
end
if filters.garage then
whereClauseCrumbs[#whereClauseCrumbs+1] = 'garage = ?'
placeholders[#placeholders+1] = filters.garage
end

return string.format(' WHERE %s', table.concat(whereClauseCrumbs, ' AND ')), placeholders
end
Expand Down

0 comments on commit a71aaf8

Please sign in to comment.