@@ -215,12 +215,12 @@ defmodule ReqCHTest do
215215
216216 test "a query with Date(Time) params" do
217217 utc_now = ~U[ 2024-12-20 05:44:53.855679Z]
218- naive_now = DateTime . to_naive ( utc_now )
218+ utc_now_seconds = DateTime . truncate ( utc_now , :second )
219219 utc_today = DateTime . to_date ( utc_now )
220220
221221 params = [
222222 utc_now: utc_now ,
223- naive_now: naive_now ,
223+ utc_now_seconds: utc_now_seconds ,
224224 utc_today: utc_today
225225 ]
226226
@@ -229,17 +229,24 @@ defmodule ReqCHTest do
229229 ReqCH . new ( ) ,
230230 """
231231 SELECT
232- {utc_now:DateTime},
233232 {utc_now:DateTime64(6)},
234- {naive_now:DateTime},
235- {naive_now:DateTime64(6)},
236- {date:Date}
233+ {utc_now_seconds:DateTime},
234+ {utc_today:Date}
235+ FORMAT
236+ JSONCompact
237237 """ ,
238238 params
239239 )
240240
241241 assert response . status == 200
242- assert response . body == ""
242+
243+ assert response . body [ "data" ] == [
244+ [
245+ "2024-12-20 05:44:53.855679" ,
246+ "2024-12-20 05:44:53" ,
247+ "2024-12-20"
248+ ]
249+ ]
243250 end
244251
245252 # https://clickhouse.com/docs/en/interfaces/http#tabs-in-url-parameters
@@ -252,17 +259,21 @@ defmodule ReqCHTest do
252259 ]
253260
254261 response =
255- ReqCH . query ( ReqCH . new ( ) , "SELECT {tab:String}, {newline:String}, {both:String}" , params )
262+ ReqCH . query! (
263+ ReqCH . new ( ) ,
264+ "SELECT {tab:String}, {newline:String}, {both:String} FORMAT JSONCompact" ,
265+ params
266+ )
256267
257268 assert response . status == 200
258- assert response . body == "a\t b\ n c\n "
269+ assert response . body [ "data" ] == [ [ "a\t b" , "c \n d" , "a \t b \ n c\t \n d" ] ]
259270 end
260271
261272 test "a query with arrays" do
262273 params = [
263- array: [ "a" , "b" , "c" ] ,
274+ array: [ "a" , "b" , "c" , "a \t b \n c \t \n d" ] ,
264275 empty_array: [ ] ,
265- nested_array: [ [ "a" , "b" ] , [ "c" , "d" ] ] ,
276+ nested_array: [ [ "a" , "b" ] , [ "c" , "d" ] , [ "a \t b \n c \t \n d" ] ] ,
266277 date_array: [ ~D[ 2024-12-20] , ~D[ 2024-12-21] ]
267278 ]
268279
@@ -275,12 +286,22 @@ defmodule ReqCHTest do
275286 {empty_array:Array(String)},
276287 {nested_array:Array(Array(String))},
277288 {date_array:Array(Date)}
289+ FORMAT
290+ JSONCompact
278291 """ ,
279292 params
280293 )
281294
282295 assert response . status == 200
283- assert response . body == ""
296+
297+ assert response . body [ "data" ] == [
298+ [
299+ [ "a" , "b" , "c" , "a\t b\n c\t \n d" ] ,
300+ [ ] ,
301+ [ [ "a" , "b" ] , [ "c" , "d" ] , [ "a\t b\n c\t \n d" ] ] ,
302+ [ "2024-12-20" , "2024-12-21" ]
303+ ]
304+ ]
284305 end
285306
286307 test "a query with tuples" do
@@ -305,7 +326,14 @@ defmodule ReqCHTest do
305326 )
306327
307328 assert response . status == 200
308- assert response . body == ""
329+
330+ assert response . body ==
331+ """
332+ (1,'a','2024-12-20')\t \
333+ ()\t \
334+ ((1,'a'),(2,'b'))\t \
335+ ('2024-12-20','2024-12-21')
336+ """
309337 end
310338
311339 test "a query with maps" do
@@ -325,12 +353,22 @@ defmodule ReqCHTest do
325353 {empty_map:Map(String, UInt8)},
326354 {nested_map:Map(String, Map(String, UInt8))},
327355 {date_map:Map(String, Date)}
356+ FORMAT
357+ JSONCompact
328358 """ ,
329359 params
330360 )
331361
332362 assert response . status == 200
333- assert response . body == ""
363+
364+ assert response . body [ "data" ] == [
365+ [
366+ % { "a" => 1 , "b" => 2 } ,
367+ % { } ,
368+ % { "a" => % { "b" => 1 } , "c" => % { "d" => 2 } } ,
369+ % { "a" => "2024-12-20" , "b" => "2024-12-21" }
370+ ]
371+ ]
334372 end
335373
336374 test "a query with unknown database" do
0 commit comments