Skip to content

Commit

Permalink
add json as string example test
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslandoga committed Feb 22, 2025
1 parent 388570e commit 0e4239c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/ch/connection_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,32 @@ defmodule Ch.ConnectionTest do
assert_raise ArgumentError, fn -> Ch.query!(conn, "SELECT o FROM json") end
end

test "json as string", %{conn: conn} do

Check failure on line 585 in test/ch/connection_test.exs

View workflow job for this annotation

GitHub Actions / test (1.17.3, 27.2.1, 24.12.2.29, UTC)

test types json as string (Ch.ConnectionTest)
assert Ch.query!(conn, ~s|select '{"answer":42}'::JSON::String|, [],
settings: [enable_json_type: 1]
).rows == [[~s|{"answer":"42"}|]]

Ch.query!(conn, "CREATE TABLE test_json_as_string(json JSON) ENGINE = Memory", [],
settings: [enable_json_type: 1]
)

Ch.query!(
conn,
"INSERT INTO test_json_as_string(json) FORMAT RowBinary",
_rows = [[Jason.encode_to_iodata!(%{"a" => 42})], [Jason.encode_to_iodata!(%{"b" => 10})]],
types: [:string],
settings: [
enable_json_type: 1,
input_format_binary_read_json_as_string: 1
]
)

assert Ch.query!(conn, "select json::String from test_json_as_string", [],
settings: [enable_json_type: 1]
).rows ==
[[~s|{"a":"42"}|], [~s|{"b":"10"}|]]
end

# TODO enum16

test "enum8", %{conn: conn} do
Expand Down

0 comments on commit 0e4239c

Please sign in to comment.