@@ -7,7 +7,7 @@ const SQL = require('./SQL')
7
7
const unsafe = SQL . unsafe
8
8
const quoteIdent = SQL . quoteIdent
9
9
10
- test ( 'SQL helper - build complex query with append' , t => {
10
+ test ( 'SQL helper - build complex query with append' , async t => {
11
11
const name = 'Team 5'
12
12
const description = 'description'
13
13
const teamId = 7
@@ -29,10 +29,9 @@ test('SQL helper - build complex query with append', t => {
29
29
`UPDATE teams SET name = '${ name } ', description = '${ description } ' WHERE id = ${ teamId } AND org_id = '${ organizationId } '`
30
30
)
31
31
t . same ( sql . values , [ name , description , teamId , organizationId ] )
32
- t . end ( )
33
32
} )
34
33
35
- test ( 'SQL helper - multiline' , t => {
34
+ test ( 'SQL helper - multiline' , async t => {
36
35
const name = 'Team 5'
37
36
const description = 'description'
38
37
const teamId = 7
@@ -56,11 +55,9 @@ test('SQL helper - multiline', t => {
56
55
`UPDATE teams SET name = '${ name } ', description = '${ description } '\nWHERE id = ${ teamId } AND org_id = '${ organizationId } '`
57
56
)
58
57
t . same ( sql . values , [ name , description , teamId , organizationId ] )
59
-
60
- t . end ( )
61
58
} )
62
59
63
- test ( 'SQL helper - multiline with emtpy lines' , t => {
60
+ test ( 'SQL helper - multiline with emtpy lines' , async t => {
64
61
const name = 'Team 5'
65
62
const description = 'description'
66
63
const teamId = 7
@@ -86,10 +83,9 @@ test('SQL helper - multiline with emtpy lines', t => {
86
83
`UPDATE teams SET name = '${ name } ', description = '${ description } '\nWHERE id = ${ teamId } AND org_id = '${ organizationId } '\nRETURNING id`
87
84
)
88
85
t . same ( sql . values , [ name , description , teamId , organizationId ] )
89
- t . end ( )
90
86
} )
91
87
92
- test ( 'SQL helper - build complex query with glue' , t => {
88
+ test ( 'SQL helper - build complex query with glue' , async t => {
93
89
const name = 'Team 5'
94
90
const description = 'description'
95
91
const teamId = 7
@@ -117,10 +113,9 @@ test('SQL helper - build complex query with glue', t => {
117
113
`UPDATE teams SET name = '${ name } ' , description = '${ description } ' WHERE id = ${ teamId } AND org_id = '${ organizationId } '`
118
114
)
119
115
t . same ( sql . values , [ name , description , teamId , organizationId ] )
120
- t . end ( )
121
116
} )
122
117
123
- test ( 'SQL helper - build complex query with glue - regression #13' , t => {
118
+ test ( 'SQL helper - build complex query with glue - regression #13' , async t => {
124
119
const name = 'Team 5'
125
120
const ids = [ 1 , 2 , 3 ] . map ( id => SQL `${ id } ` )
126
121
@@ -136,10 +131,9 @@ test('SQL helper - build complex query with glue - regression #13', t => {
136
131
`UPDATE teams SET name = '${ name } ' WHERE id IN (1 , 2 , 3 )`
137
132
)
138
133
t . same ( sql . values , [ name , 1 , 2 , 3 ] )
139
- t . end ( )
140
134
} )
141
135
142
- test ( 'SQL helper - build complex query with glue - regression #17' , t => {
136
+ test ( 'SQL helper - build complex query with glue - regression #17' , async t => {
143
137
const ids = [ 1 , 2 , 3 ] . map ( id => SQL `(${ id } )` )
144
138
145
139
const sql = SQL `INSERT INTO users (id) VALUES `
@@ -149,10 +143,9 @@ test('SQL helper - build complex query with glue - regression #17', t => {
149
143
t . equal ( sql . sql , 'INSERT INTO users (id) VALUES (?) , (?) , (?)' )
150
144
t . equal ( sql . debug , 'INSERT INTO users (id) VALUES (1) , (2) , (3)' )
151
145
t . same ( sql . values , [ 1 , 2 , 3 ] )
152
- t . end ( )
153
146
} )
154
147
155
- test ( 'SQL helper - build complex query with static glue - regression #17' , t => {
148
+ test ( 'SQL helper - build complex query with static glue - regression #17' , async t => {
156
149
const ids = [ 1 , 2 , 3 ] . map ( id => SQL `(${ id } )` )
157
150
158
151
const sql = SQL `INSERT INTO users (id) VALUES `
@@ -162,10 +155,9 @@ test('SQL helper - build complex query with static glue - regression #17', t =>
162
155
t . equal ( sql . sql , 'INSERT INTO users (id) VALUES (?) , (?) , (?)' )
163
156
t . equal ( sql . debug , 'INSERT INTO users (id) VALUES (1) , (2) , (3)' )
164
157
t . same ( sql . values , [ 1 , 2 , 3 ] )
165
- t . end ( )
166
158
} )
167
159
168
- test ( 'SQL helper - build complex query with append and glue' , t => {
160
+ test ( 'SQL helper - build complex query with append and glue' , async t => {
169
161
const updates = [ ]
170
162
const v1 = 'v1'
171
163
const v2 = 'v2'
@@ -199,10 +191,9 @@ test('SQL helper - build complex query with append and glue', t => {
199
191
"TEST QUERY glue pieces FROM v1 = 'v1' , v2 = 'v2' , v3 = 'v3' , v4 = 'v4' , v5 = 'v5' WHERE v6 = 'v6' AND v7 = 'v7'"
200
192
)
201
193
t . same ( sql . values , [ v1 , v2 , v3 , v4 , v5 , v6 , v7 ] )
202
- t . end ( )
203
194
} )
204
195
205
- test ( 'SQL helper - build complex query with append' , t => {
196
+ test ( 'SQL helper - build complex query with append' , async t => {
206
197
const v1 = 'v1'
207
198
const v2 = 'v2'
208
199
const v3 = 'v3'
@@ -233,10 +224,9 @@ test('SQL helper - build complex query with append', t => {
233
224
"TEST QUERY glue pieces FROM v1 = 'v1', v2 = 'v2', v3 = 'v3', v4 = 'v4', v5 = 'v5' WHERE v6 = 'v6' AND v7 = 'v7'"
234
225
)
235
226
t . same ( sql . values , [ v1 , v2 , v3 , v4 , v5 , v6 , v7 ] )
236
- t . end ( )
237
227
} )
238
228
239
- test ( 'SQL helper - build complex query with append passing simple strings and template strings' , t => {
229
+ test ( 'SQL helper - build complex query with append passing simple strings and template strings' , async t => {
240
230
const v1 = 'v1'
241
231
const v2 = 'v2'
242
232
const v3 = 'v3'
@@ -265,10 +255,9 @@ test('SQL helper - build complex query with append passing simple strings and te
265
255
"TEST QUERY glue pieces FROM v1 = 'v1', v2 = 'v2', v3 = 'v3', v4 = 'v4', v5 = 'v5', v6 = v6 WHERE v6 = 'v6' AND v7 = 'v7' AND v8 = v8"
266
256
)
267
257
t . same ( sql . values , [ v1 , v2 , v3 , v4 , v5 , v6 , v7 ] )
268
- t . end ( )
269
258
} )
270
259
271
- test ( 'SQL helper - will throw an error if append is called without using SQL' , t => {
260
+ test ( 'SQL helper - will throw an error if append is called without using SQL' , async t => {
272
261
const sql = SQL `TEST QUERY glue pieces FROM `
273
262
try {
274
263
sql . append ( 'v1 = v1' )
@@ -279,10 +268,9 @@ test('SQL helper - will throw an error if append is called without using SQL', t
279
268
'"append" accepts only template string prefixed with SQL (SQL`...`)'
280
269
)
281
270
}
282
- t . end ( )
283
271
} )
284
272
285
- test ( 'SQL helper - build string using append with and without unsafe flag' , t => {
273
+ test ( 'SQL helper - build string using append with and without unsafe flag' , async t => {
286
274
const v2 = 'v2'
287
275
const longName = 'whateverThisIs'
288
276
const sql = SQL `TEST QUERY glue pieces FROM test WHERE test1 == test2`
@@ -301,10 +289,9 @@ test('SQL helper - build string using append with and without unsafe flag', t =>
301
289
)
302
290
t . equal ( sql . values . length , 1 )
303
291
t . ok ( sql . values . includes ( v2 ) )
304
- t . end ( )
305
292
} )
306
293
307
- test ( 'SQL helper - build string using append and only unsafe' , t => {
294
+ test ( 'SQL helper - build string using append and only unsafe' , async t => {
308
295
const v2 = 'v2'
309
296
const longName = 'whateverThisIs'
310
297
@@ -328,11 +315,9 @@ test('SQL helper - build string using append and only unsafe', t => {
328
315
sql . debug ,
329
316
"TEST QUERY glue pieces FROM test WHERE test1 == test2 AND v1 = v1, AND v2 = v2 AND v3 = whateverThisIs AND v4 = 'v4'"
330
317
)
331
-
332
- t . end ( )
333
318
} )
334
319
335
- test ( 'SQL helper - handles js null values as valid `null` sql values' , t => {
320
+ test ( 'SQL helper - handles js null values as valid `null` sql values' , async t => {
336
321
const name = null
337
322
const id = 123
338
323
@@ -342,49 +327,44 @@ test('SQL helper - handles js null values as valid `null` sql values', t => {
342
327
t . equal ( sql . sql , 'UPDATE teams SET name = ? WHERE id = ?' )
343
328
t . equal ( sql . debug , `UPDATE teams SET name = null WHERE id = ${ id } ` )
344
329
t . same ( sql . values , [ name , id ] )
345
- t . end ( )
346
330
} )
347
331
348
- test ( 'SQL helper - throws when building an sql string with an `undefined` value' , t => {
332
+ test ( 'SQL helper - throws when building an sql string with an `undefined` value' , async t => {
349
333
t . throws ( ( ) => SQL `UPDATE teams SET name = ${ undefined } ` )
350
- t . end ( )
351
334
} )
352
335
353
- test ( 'empty append' , t => {
336
+ test ( 'empty append' , async t => {
354
337
const sql = SQL `UPDATE teams SET name = ${ 'team' } ` . append ( )
355
338
356
339
t . equal ( sql . text , 'UPDATE teams SET name = $1' )
357
340
t . equal ( sql . sql , 'UPDATE teams SET name = ?' )
358
341
t . equal ( sql . debug , "UPDATE teams SET name = 'team'" )
359
342
t . same ( sql . values , [ 'team' ] )
360
-
361
- t . end ( )
362
343
} )
363
344
364
- test ( 'inspect' , t => {
345
+ test ( 'inspect' , async t => {
365
346
const sql = SQL `UPDATE teams SET name = ${ 'team' } `
366
-
367
347
t . equal ( util . inspect ( sql ) , "SQL << UPDATE teams SET name = 'team' >>" )
368
- t . end ( )
369
348
} )
370
349
371
- test ( 'quoteIdent' , t => {
372
- const table = 'teams'
373
- const name = 'name'
374
- const id = 123
350
+ test ( 'quoteIdent' , async t => {
351
+ t . test ( 'simple' , async t => {
352
+ const table = 'teams'
353
+ const name = 'name'
354
+ const id = 123
375
355
376
- const sql = SQL `UPDATE ${ quoteIdent (
377
- table
378
- ) } SET name = ${ name } WHERE id = ${ id } `
356
+ const sql = SQL `UPDATE ${ quoteIdent (
357
+ table
358
+ ) } SET name = ${ name } WHERE id = ${ id } `
379
359
380
- t . equal ( sql . text , 'UPDATE "teams" SET name = $1 WHERE id = $2' )
381
- t . equal ( sql . sql , 'UPDATE " teams" SET name = ? WHERE id = ?' )
382
- t . equal ( sql . debug , `UPDATE "teams" SET name = 'name' WHERE id = ${ id } ` )
383
- t . same ( sql . values , [ name , id ] )
384
- t . end ( )
360
+ t . equal ( sql . text , 'UPDATE "teams" SET name = $1 WHERE id = $2' )
361
+ t . equal ( sql . sql , 'UPDATE ` teams` SET name = ? WHERE id = ?' )
362
+ t . equal ( sql . debug , `UPDATE "teams" SET name = 'name' WHERE id = ${ id } ` )
363
+ t . same ( sql . values , [ name , id ] )
364
+ } )
385
365
} )
386
366
387
- test ( 'unsafe' , t => {
367
+ test ( 'unsafe' , async t => {
388
368
const name = 'name'
389
369
const id = 123
390
370
@@ -394,10 +374,9 @@ test('unsafe', t => {
394
374
t . equal ( sql . sql , "UPDATE teams SET name = 'name' WHERE id = ?" )
395
375
t . equal ( sql . debug , `UPDATE teams SET name = 'name' WHERE id = ${ id } ` )
396
376
t . same ( sql . values , [ id ] )
397
- t . end ( )
398
377
} )
399
378
400
- test ( 'should be able to append query that is using "{ unsafe: true }"' , t => {
379
+ test ( 'should be able to append query that is using "{ unsafe: true }"' , async t => {
401
380
const table = 'teams'
402
381
const id = 123
403
382
@@ -424,11 +403,9 @@ test('should be able to append query that is using "{ unsafe: true }"', t => {
424
403
`SELECT * FROM teams INNER JOIN (SELECT id FROM teams WHERE id = ${ id } ) as t2 ON t2.id = id`
425
404
)
426
405
t . same ( sql . values , [ id ] )
427
-
428
- t . end ( )
429
406
} )
430
407
431
- test ( 'should be able to append query that is using "quoteIdent(...)"' , t => {
408
+ test ( 'should be able to append query that is using "quoteIdent(...)"' , async t => {
432
409
const table = 'teams'
433
410
const id = 123
434
411
@@ -444,12 +421,11 @@ test('should be able to append query that is using "quoteIdent(...)"', t => {
444
421
)
445
422
t . equal (
446
423
sql . sql ,
447
- 'SELECT * FROM " teams" INNER JOIN (SELECT id FROM " teams" WHERE id = ?) as t2 ON t2.id = id'
424
+ 'SELECT * FROM ` teams` INNER JOIN (SELECT id FROM ` teams` WHERE id = ?) as t2 ON t2.id = id'
448
425
)
449
426
t . equal (
450
427
sql . debug ,
451
428
`SELECT * FROM "teams" INNER JOIN (SELECT id FROM "teams" WHERE id = ${ id } ) as t2 ON t2.id = id`
452
429
)
453
430
t . same ( sql . values , [ id ] )
454
- t . end ( )
455
431
} )
0 commit comments