Skip to content

Commit 76c47c1

Browse files
committed
fix compile time regex for otp 28
In OTP 28 you can no longer have compile time regex, ie in a module attr. Their recommendation is to move them to functions.
1 parent cd54d43 commit 76c47c1

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

lib/new_relic/telemetry/ecto/metadata.ex

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,16 @@ defmodule NewRelic.Telemetry.Ecto.Metadata do
4343
# Exqlite: table
4444
@esc ~w(" ` [ ])
4545

46-
@capture %{
47-
select: ~r/FROM (?<table>\S+)/,
48-
insert: ~r/INSERT INTO (?<table>\S+)/,
49-
update: ~r/UPDATE (?<table>\S+)/,
50-
delete: ~r/FROM (?<table>\S+)/,
51-
create: ~r/CREATE TABLE( IF NOT EXISTS)? (?<table>\S+)/
52-
}
5346
def parse_query(operation, query) do
54-
case Regex.named_captures(@capture[operation], query) do
47+
case Regex.named_captures(capture(operation), query) do
5548
%{"table" => table} -> {operation, String.replace(table, @esc, "")}
5649
_ -> {operation, :other}
5750
end
5851
end
52+
53+
defp capture(:select), do: ~r/FROM (?<table>\S+)/
54+
defp capture(:insert), do: ~r/INSERT INTO (?<table>\S+)/
55+
defp capture(:update), do: ~r/UPDATE (?<table>\S+)/
56+
defp capture(:delete), do: ~r/FROM (?<table>\S+)/
57+
defp capture(:create), do: ~r/CREATE TABLE( IF NOT EXISTS)? (?<table>\S+)/
5958
end

0 commit comments

Comments
 (0)