Skip to content

Commit 7bd83cd

Browse files
authored
Fix error search in SQLite (#51)
SQLite does not support the ILIKE operator. We need to use the LIKE operator instead, which performs a case-insensitive match for ASCII characters. Since we are looking at stacktrace lines and module names I think that it is fair to expect ASCII characters 99%+ of the time anyway. This pull request fixes the problem by detecting the current database adapter and using LIKE or ILIKE accordingly. I've also extracted the search function out of the dashboard and unit-tested it to ensure that it works and doesn't break by mistake. Closes #50
1 parent 90b3408 commit 7bd83cd

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/error_tracker/web/live/dashboard.ex

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ defmodule ErrorTracker.Web.Live.Dashboard do
111111
end
112112

113113
defp do_filter({field, value}, query) do
114-
where(query, [error], ilike(field(error, ^field), ^"%#{value}%"))
114+
# Postgres provides the ILIKE operator which produces a case-insensitive match between two
115+
# strings. SQLite3 only supports LIKE, which is case-insensitive for ASCII characters.
116+
Repo.with_adapter(fn
117+
:postgres -> where(query, [error], ilike(field(error, ^field), ^"%#{value}%"))
118+
:sqlite -> where(query, [error], like(field(error, ^field), ^"%#{value}%"))
119+
end)
115120
end
116121
end

0 commit comments

Comments
 (0)