Skip to content

Commit

Permalink
Merge pull request #15 from DenisPushkarev/null-date-to-elixir
Browse files Browse the repository at this point in the history
parse nullable date to elixir as null
  • Loading branch information
sofakingworld authored Oct 14, 2020
2 parents 54e309c + 6fd78c9 commit 23b8c3b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/pillar/type_convert/to_elixir.ex
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ defmodule Pillar.TypeConvert.ToElixir do
datetime
end

def convert("Date", "0000-00-00") do
nil
end

def convert("Date", value) do
Date.from_iso8601!(value)
end
Expand Down
18 changes: 18 additions & 0 deletions test/pillar_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,24 @@ defmodule PillarTest do
assert {:ok, [%{"today()" => %Date{}}]} = Pillar.select(conn, sql)
end

test "empty Date test", %{conn: conn} do
table_name = "lc_table_empty_date_#{@timestamp}"

create_table_sql = """
CREATE TABLE IF NOT EXISTS #{table_name} (field Nullable(Date)) ENGINE = Memory
"""

insert_query_sql = """
INSERT INTO #{table_name} SELECT null
"""

assert {:ok, ""} = Pillar.query(conn, create_table_sql)
assert {:ok, ""} = Pillar.query(conn, insert_query_sql)

assert {:ok, [%{"field" => nil}]} =
Pillar.query(conn, "SELECT * FROM #{table_name} LIMIT 1 FORMAT JSON")
end

test "DateTime test", %{conn: conn} do
sql = "SELECT now()"

Expand Down

0 comments on commit 23b8c3b

Please sign in to comment.