1
1
import type { QueryParams } from '@clickhouse/client-common'
2
+ import { TupleParam } from '@clickhouse/client-common'
2
3
import { type ClickHouseClient } from '@clickhouse/client-common'
3
4
import { createTestClient } from '../utils'
4
5
@@ -92,6 +93,85 @@ describe('select with query binding', () => {
92
93
] )
93
94
} )
94
95
96
+ it ( 'handles tuples in a parametrized query' , async ( ) => {
97
+ const rs = await client . query ( {
98
+ query : 'SELECT {var: Tuple(Int32, String, String, String)} AS result' ,
99
+ format : 'JSONEachRow' ,
100
+ query_params : {
101
+ var : new TupleParam ( [ 42 , 'foo' , "foo_'_bar" , 'foo_\t_bar' ] ) ,
102
+ } ,
103
+ } )
104
+ expect ( await rs . json ( ) ) . toEqual ( [
105
+ {
106
+ result : [ 42 , 'foo' , "foo_'_bar" , 'foo_\t_bar' ] ,
107
+ } ,
108
+ ] )
109
+ } )
110
+
111
+ it ( 'handles arrays of tuples in a parametrized query' , async ( ) => {
112
+ const rs = await client . query ( {
113
+ query :
114
+ 'SELECT {var: Array(Tuple(Int32, String, String, String))} AS result' ,
115
+ format : 'JSONEachRow' ,
116
+ query_params : {
117
+ var : [ new TupleParam ( [ 42 , 'foo' , "foo_'_bar" , 'foo_\t_bar' ] ) ] ,
118
+ } ,
119
+ } )
120
+ expect ( await rs . json ( ) ) . toEqual ( [
121
+ {
122
+ result : [ [ 42 , 'foo' , "foo_'_bar" , 'foo_\t_bar' ] ] ,
123
+ } ,
124
+ ] )
125
+ } )
126
+
127
+ it ( 'handles maps with tuples in a parametrized query' , async ( ) => {
128
+ const rs = await client . query ( {
129
+ query :
130
+ 'SELECT {var: Map(Int32, Tuple(Int32, String, String, String))} AS result' ,
131
+ format : 'JSONEachRow' ,
132
+ query_params : {
133
+ var : new Map ( [
134
+ [ 42 , new TupleParam ( [ 144 , 'foo' , "foo_'_bar" , 'foo_\t_bar' ] ) ] ,
135
+ ] ) ,
136
+ } ,
137
+ } )
138
+ expect ( await rs . json ( ) ) . toEqual ( [
139
+ {
140
+ result : {
141
+ 42 : [ 144 , 'foo' , "foo_'_bar" , 'foo_\t_bar' ] ,
142
+ } ,
143
+ } ,
144
+ ] )
145
+ } )
146
+
147
+ it ( 'handles maps with nested arrays in a parametrized query' , async ( ) => {
148
+ const rs = await client . query ( {
149
+ query : 'SELECT {var: Map(Int32, Array(Array(Int32)))} AS result' ,
150
+ format : 'JSONEachRow' ,
151
+ query_params : {
152
+ var : new Map ( [
153
+ [
154
+ 42 ,
155
+ [
156
+ [ 1 , 2 , 3 ] ,
157
+ [ 4 , 5 ] ,
158
+ ] ,
159
+ ] ,
160
+ ] ) ,
161
+ } ,
162
+ } )
163
+ expect ( await rs . json ( ) ) . toEqual ( [
164
+ {
165
+ result : {
166
+ 42 : [
167
+ [ 1 , 2 , 3 ] ,
168
+ [ 4 , 5 ] ,
169
+ ] ,
170
+ } ,
171
+ } ,
172
+ ] )
173
+ } )
174
+
95
175
describe ( 'Date(Time)' , ( ) => {
96
176
it ( 'handles Date in a parameterized query' , async ( ) => {
97
177
const rs = await client . query ( {
@@ -201,7 +281,7 @@ describe('select with query binding', () => {
201
281
expect ( response ) . toBe ( '"co\'nca\'t"\n' )
202
282
} )
203
283
204
- it ( 'handles an object a parameterized query' , async ( ) => {
284
+ it ( 'handles an object as a map a parameterized query' , async ( ) => {
205
285
const rs = await client . query ( {
206
286
query : 'SELECT mapKeys({obj: Map(String, UInt32)})' ,
207
287
format : 'CSV' ,
@@ -235,6 +315,7 @@ describe('select with query binding', () => {
235
315
bar = 1 ,
236
316
qaz = 2 ,
237
317
}
318
+
238
319
const rs = await client . query ( {
239
320
query :
240
321
'SELECT * FROM system.numbers WHERE number = {filter: Int64} LIMIT 1' ,
@@ -253,6 +334,7 @@ describe('select with query binding', () => {
253
334
foo = 'foo' ,
254
335
bar = 'bar' ,
255
336
}
337
+
256
338
const rs = await client . query ( {
257
339
query : 'SELECT concat({str1: String},{str2: String})' ,
258
340
format : 'TabSeparated' ,
@@ -284,8 +366,10 @@ describe('select with query binding', () => {
284
366
await expectAsync (
285
367
client . query ( {
286
368
query : `
287
- SELECT * FROM system.numbers
288
- WHERE number > {min_limit: UInt64} LIMIT 3
369
+ SELECT *
370
+ FROM system.numbers
371
+ WHERE number > {min_limit: UInt64}
372
+ LIMIT 3
289
373
` ,
290
374
} ) ,
291
375
) . toBeRejectedWith (
0 commit comments