Skip to content

Commit

Permalink
Fix error search in SQLite (#51)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
crbelaus authored Aug 20, 2024
1 parent 90b3408 commit 7bd83cd
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/error_tracker/web/live/dashboard.ex
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ defmodule ErrorTracker.Web.Live.Dashboard do
end

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

0 comments on commit 7bd83cd

Please sign in to comment.