Skip to content

Commit

Permalink
Add support for decimal_encode(nil) (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
philipgiuliani authored Jan 18, 2024
1 parent 739bde1 commit fe8519e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/ecto/adapters/sqlite3/codec.ex
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ defmodule Ecto.Adapters.SQLite3.Codec do
def bool_encode(false), do: {:ok, 0}
def bool_encode(true), do: {:ok, 1}

def decimal_encode(nil), do: {:ok, nil}

def decimal_encode(%Decimal{} = x) do
{:ok, Decimal.to_string(x, :normal)}
end

# def decimal_encode(x), do: {:ok, x}

def time_encode(value) do
{:ok, value}
end
Expand Down
11 changes: 11 additions & 0 deletions test/ecto/adapters/sqlite3/codec_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ defmodule Ecto.Adapters.SQLite3.CodecTest do
end
end

describe ".decimal_encode/1" do
test "nil" do
{:ok, nil} = Codec.decimal_encode(nil)
end

test "decimal" do
decimal = Decimal.new("2.5")
{:ok, "2.5"} = Codec.decimal_encode(decimal)
end
end

describe ".time_decode/1" do
test "nil" do
{:ok, nil} = Codec.time_decode(nil)
Expand Down

0 comments on commit fe8519e

Please sign in to comment.