@@ -430,61 +430,76 @@ function testTypedValues(next: (err?: Error) => void) {
430430
431431 // query with typed result and typed values
432432 type UserRow = { id : number ; email : string } ;
433- connection . query < UserRow [ ] , [ number ] > ( 'SELECT * FROM users WHERE id = ?' , [ 1 ] , ( err : SqlError | null , rows ?: UserRow [ ] ) => {
434- if ( err ) return next ( err ) ;
435- if ( rows === undefined ) return next ( new Error ( 'rows is undefined' ) ) ;
436- console . log ( rows [ 0 ] . id ) ;
437- console . log ( rows [ 0 ] . email ) ;
438-
439- // execute with typed result and typed values
440- connection . execute < UserRow [ ] , [ number ] > ( 'SELECT * FROM users WHERE id = ?' , [ 1 ] , ( err : SqlError | null , rows ?: UserRow [ ] ) => {
433+ connection . query < UserRow [ ] , [ number ] > (
434+ 'SELECT * FROM users WHERE id = ?' ,
435+ [ 1 ] ,
436+ ( err : SqlError | null , rows ?: UserRow [ ] ) => {
441437 if ( err ) return next ( err ) ;
442438 if ( rows === undefined ) return next ( new Error ( 'rows is undefined' ) ) ;
443439 console . log ( rows [ 0 ] . id ) ;
440+ console . log ( rows [ 0 ] . email ) ;
444441
445- // batch with typed values
446- type InsertParams = [ number , string ] [ ] ;
447- connection . batch < UpsertResult , InsertParams > ( 'INSERT INTO users VALUE (?,?)' , [
448- [ 1 , 'a@b.com' ] ,
449- [ 2 , 'c@d.com' ]
450- ] , ( err : SqlError | null , res ?: UpsertResult ) => {
451- if ( err ) return next ( err ) ;
452- if ( res === undefined ) return next ( new Error ( 'res is undefined' ) ) ;
453- console . log ( res . affectedRows ) ;
454-
455- // prepare with typed values
456- type PrepareParams = [ string , Buffer , Buffer ] ;
457- connection . prepare < PrepareParams > ( 'INSERT INTO users VALUES (?, ?, ?)' , ( err : SqlError | null , stmt ?: Prepare < PrepareParams > ) => {
442+ // execute with typed result and typed values
443+ connection . execute < UserRow [ ] , [ number ] > (
444+ 'SELECT * FROM users WHERE id = ?' ,
445+ [ 1 ] ,
446+ ( err : SqlError | null , rows ?: UserRow [ ] ) => {
458447 if ( err ) return next ( err ) ;
459- if ( stmt === undefined ) return next ( new Error ( 'stmt is undefined' ) ) ;
460- console . log ( stmt . id ) ;
461- stmt . execute ( [ 'email' , Buffer . from ( 'hash' ) , Buffer . from ( 'salt' ) ] , ( err : SqlError | null ) => {
462- if ( err ) return next ( err ) ;
463- const stream = stmt ! . executeStream ( [ 'email' , Buffer . from ( 'hash' ) , Buffer . from ( 'salt' ) ] ) ;
464- stream . on ( 'data' , ( row : unknown ) => console . log ( row ) ) ;
465- stmt ! . close ( ) ;
466-
467- // queryStream with typed values
468- connection . queryStream < [ number ] > ( 'SELECT * FROM users WHERE id = ?' , [ 1 ] ) ;
448+ if ( rows === undefined ) return next ( new Error ( 'rows is undefined' ) ) ;
449+ console . log ( rows [ 0 ] . id ) ;
469450
470- // backward compat: no type argument still works (defaults to any)
471- connection . query ( 'SELECT 1' , ( err : SqlError | null ) => {
451+ // batch with typed values
452+ type InsertParams = [ number , string ] [ ] ;
453+ connection . batch < UpsertResult , InsertParams > (
454+ 'INSERT INTO users VALUE (?,?)' ,
455+ [
456+ [ 1 , 'a@b.com' ] ,
457+ [ 2 , 'c@d.com' ]
458+ ] ,
459+ ( err : SqlError | null , res ?: UpsertResult ) => {
472460 if ( err ) return next ( err ) ;
473- connection . prepare ( 'SELECT ?' , ( err : SqlError | null , stmtAny ?: Prepare ) => {
474- if ( err ) return next ( err ) ;
475- if ( stmtAny === undefined ) return next ( new Error ( 'stmtAny is undefined' ) ) ;
476- stmtAny . execute ( [ 1 ] , ( err : SqlError | null ) => {
461+ if ( res === undefined ) return next ( new Error ( 'res is undefined' ) ) ;
462+ console . log ( res . affectedRows ) ;
463+
464+ // prepare with typed values
465+ type PrepareParams = [ string , Buffer , Buffer ] ;
466+ connection . prepare < PrepareParams > (
467+ 'INSERT INTO users VALUES (?, ?, ?)' ,
468+ ( err : SqlError | null , stmt ?: Prepare < PrepareParams > ) => {
477469 if ( err ) return next ( err ) ;
478- stmtAny ! . close ( ) ;
479- connection . end ( ( ) => next ( ) ) ;
480- } ) ;
481- } ) ;
482- } ) ;
483- } ) ;
484- } ) ;
485- } ) ;
486- } ) ;
487- } ) ;
470+ if ( stmt === undefined ) return next ( new Error ( 'stmt is undefined' ) ) ;
471+ console . log ( stmt . id ) ;
472+ stmt . execute ( [ 'email' , Buffer . from ( 'hash' ) , Buffer . from ( 'salt' ) ] , ( err : SqlError | null ) => {
473+ if ( err ) return next ( err ) ;
474+ const stream = stmt ! . executeStream ( [ 'email' , Buffer . from ( 'hash' ) , Buffer . from ( 'salt' ) ] ) ;
475+ stream . on ( 'data' , ( row : unknown ) => console . log ( row ) ) ;
476+ stmt ! . close ( ) ;
477+
478+ // queryStream with typed values
479+ connection . queryStream < [ number ] > ( 'SELECT * FROM users WHERE id = ?' , [ 1 ] ) ;
480+
481+ // backward compat: no type argument still works (defaults to any)
482+ connection . query ( 'SELECT 1' , ( err : SqlError | null ) => {
483+ if ( err ) return next ( err ) ;
484+ connection . prepare ( 'SELECT ?' , ( err : SqlError | null , stmtAny ?: Prepare ) => {
485+ if ( err ) return next ( err ) ;
486+ if ( stmtAny === undefined ) return next ( new Error ( 'stmtAny is undefined' ) ) ;
487+ stmtAny . execute ( [ 1 ] , ( err : SqlError | null ) => {
488+ if ( err ) return next ( err ) ;
489+ stmtAny ! . close ( ) ;
490+ connection . end ( ( ) => next ( ) ) ;
491+ } ) ;
492+ } ) ;
493+ } ) ;
494+ } ) ;
495+ }
496+ ) ;
497+ }
498+ ) ;
499+ }
500+ ) ;
501+ }
502+ ) ;
488503}
489504
490505function testTypedValuesPool ( next : ( err ?: Error ) => void ) {
@@ -497,21 +512,29 @@ function testTypedValuesPool(next: (err?: Error) => void) {
497512 console . log ( rows [ 0 ] . id ) ;
498513
499514 type InsertParams = [ number , string ] [ ] ;
500- pool . batch < UpsertResult , InsertParams > ( 'INSERT INTO users VALUE (?,?)' , [
501- [ 1 , 'a@b.com' ] ,
502- [ 2 , 'c@d.com' ]
503- ] , ( err : SqlError | null , res ?: UpsertResult ) => {
504- if ( err ) return next ( err ) ;
505- if ( res === undefined ) return next ( new Error ( 'res is undefined' ) ) ;
506- console . log ( res . affectedRows ) ;
507-
508- pool . execute < UserRow [ ] , [ number ] > ( 'SELECT * FROM users WHERE id = ?' , [ 1 ] , ( err : SqlError | null , rows ?: UserRow [ ] ) => {
515+ pool . batch < UpsertResult , InsertParams > (
516+ 'INSERT INTO users VALUE (?,?)' ,
517+ [
518+ [ 1 , 'a@b.com' ] ,
519+ [ 2 , 'c@d.com' ]
520+ ] ,
521+ ( err : SqlError | null , res ?: UpsertResult ) => {
509522 if ( err ) return next ( err ) ;
510- if ( rows === undefined ) return next ( new Error ( 'rows is undefined' ) ) ;
511- console . log ( rows [ 0 ] . id ) ;
512- pool . end ( ( ) => next ( ) ) ;
513- } ) ;
514- } ) ;
523+ if ( res === undefined ) return next ( new Error ( 'res is undefined' ) ) ;
524+ console . log ( res . affectedRows ) ;
525+
526+ pool . execute < UserRow [ ] , [ number ] > (
527+ 'SELECT * FROM users WHERE id = ?' ,
528+ [ 1 ] ,
529+ ( err : SqlError | null , rows ?: UserRow [ ] ) => {
530+ if ( err ) return next ( err ) ;
531+ if ( rows === undefined ) return next ( new Error ( 'rows is undefined' ) ) ;
532+ console . log ( rows [ 0 ] . id ) ;
533+ pool . end ( ( ) => next ( ) ) ;
534+ }
535+ ) ;
536+ }
537+ ) ;
515538 } ) ;
516539}
517540
0 commit comments