Skip to content

Commit

Permalink
Add convert decimal (#29)
Browse files Browse the repository at this point in the history
* Add convertation from clickhouse decimal type

Co-authored-by: Алексей Редькин <[email protected]>
  • Loading branch information
alexxero and Алексей Редькин authored Oct 26, 2021
1 parent 33c684b commit a6c7e39
Show file tree
Hide file tree
Showing 2 changed files with 20 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 @@ -90,4 +90,8 @@ defmodule Pillar.TypeConvert.ToElixir do
] and is_number(value) do
value
end

def convert("Decimal" <> _decimal_subtypes, value) do
value
end
end
16 changes: 16 additions & 0 deletions test/pillar_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,22 @@ defmodule PillarTest do
})
end

test "Decimal test", %{conn: conn} do
create_table_sql = """
CREATE TABLE IF NOT EXISTS decimal_table (field Decimal64(2)) ENGINE = Memory
"""

insert_query_sql = """
INSERT INTO decimal_table VALUES (500000.05)
"""

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

assert {:ok, [%{"field" => 500_000.05}]} =
Pillar.select(conn, "SELECT * FROM decimal_table LIMIT 1")
end

test "Float tests", %{conn: conn} do
sql = ~s(
SELECT
Expand Down

0 comments on commit a6c7e39

Please sign in to comment.