Skip to content

Commit

Permalink
oops2
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Rychlewski authored and Greg Rychlewski committed Aug 6, 2024
1 parent 104ca6d commit 636003b
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/postgrex/extensions/interval.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@ defmodule Postgrex.Extensions.Interval do
import Postgrex.BinaryUtils, warn: false
use Postgrex.BinaryExtension, send: "interval_send"

def init(opts), do: Keyword.get(opts, :interval_decode_type, Postgrex.Interval)
def init(opts) do
case Keyword.get(opts, :interval_decode_type, Postgrex.Interval) do
type when type in [Postgrex.Interval, Duration] ->
type

other ->
raise ArgumentError,
"#{inspect(other)} is not valid for `:interval_decode_type`. Please use either `Postgrex.Interval` or `Duration`"
end
end

if Code.ensure_loaded?(Duration) do
import Bitwise, warn: false
Expand Down Expand Up @@ -116,9 +125,4 @@ defmodule Postgrex.Extensions.Interval do
microsecond: {microseconds, precision}
)
end

def decode_interval(_, _, _, _, type) do
raise ArgumentError,
"#{inspect(type)} is not valid for `:interval_decode_type`. Please use either `Postgrex.Interval` or `Duration`"
end
end

0 comments on commit 636003b

Please sign in to comment.