@@ -241,6 +241,79 @@ Deno.test(
241241 ) ,
242242) ;
243243
244+ Deno . test (
245+ "Custom decoders with arrays" ,
246+ withClient (
247+ async ( client ) => {
248+ const result = await client . queryObject (
249+ `SELECT
250+ ARRAY[true, false, true] AS _bool_array,
251+ ARRAY['2024-01-01'::date, '2024-01-02'::date, '2024-01-03'::date] AS _date_array,
252+ ARRAY[1.5:: REAL, 2.5::REAL, 3.5::REAL] AS _float_array,
253+ ARRAY[10, 20, 30] AS _int_array,
254+ ARRAY[
255+ '{"key1": "value1", "key2": "value2"}'::jsonb,
256+ '{"key3": "value3", "key4": "value4"}'::jsonb,
257+ '{"key5": "value5", "key6": "value6"}'::jsonb
258+ ] AS _jsonb_array,
259+ ARRAY['string1', 'string2', 'string3'] AS _text_array
260+ ;` ,
261+ ) ;
262+
263+ assertEquals ( result . rows , [
264+ {
265+ _bool_array : [
266+ { boolean : true } ,
267+ { boolean : false } ,
268+ { boolean : true } ,
269+ ] ,
270+ _date_array : [
271+ new Date ( "2024-01-11T00:00:00.000Z" ) ,
272+ new Date ( "2024-01-12T00:00:00.000Z" ) ,
273+ new Date ( "2024-01-13T00:00:00.000Z" ) ,
274+ ] ,
275+ _float_array : [ 15 , 25 , 35 ] ,
276+ _int_array : [ 110 , 120 , 130 ] ,
277+ _jsonb_array : [
278+ { key1 : "value1" , key2 : "value2" } ,
279+ { key3 : "value3" , key4 : "value4" } ,
280+ { key5 : "value5" , key6 : "value6" } ,
281+ ] ,
282+ _text_array : [ "string1_!" , "string2_!" , "string3_!" ] ,
283+ } ,
284+ ] ) ;
285+ } ,
286+ {
287+ controls : {
288+ decoders : {
289+ // convert to object
290+ [ Oid . bool ] : ( value : string ) => ( { boolean : value === "t" } ) ,
291+ // 1082 = date : convert to date and add 10 days
292+ "1082" : ( value : string ) => {
293+ const d = new Date ( value ) ;
294+ return new Date ( d . setDate ( d . getDate ( ) + 10 ) ) ;
295+ } ,
296+ // multiply by 20, should not be used!
297+ float4 : ( value : string ) => parseFloat ( value ) * 20 ,
298+ // multiply by 10
299+ float4_array : ( value : string , _ , parseArray ) =>
300+ parseArray ( value , ( v ) => parseFloat ( v ) * 10 ) ,
301+ // return 0, should not be used!
302+ [ Oid . int4 ] : ( ) => 0 ,
303+ // add 100
304+ [ Oid . int4_array ] : ( value : string , _ , parseArray ) =>
305+ parseArray ( value , ( v ) => parseInt ( v , 10 ) + 100 ) ,
306+ // split string and reverse, should not be used!
307+ [ Oid . text ] : ( value : string ) => value . split ( "" ) . reverse ( ) ,
308+ // 1009 = text_array : append "_!" to each string
309+ 1009 : ( value : string , _ , parseArray ) =>
310+ parseArray ( value , ( v ) => `${ v } _!` ) ,
311+ } ,
312+ } ,
313+ } ,
314+ ) ,
315+ ) ;
316+
244317Deno . test (
245318 "Custom decoder precedence" ,
246319 withClient (
0 commit comments