@@ -427,7 +427,61 @@ describe('Sequelize CRUD Repository (integration)', () => {
427427 expect ( queryResult [ 0 ] ) . property ( 'name' ) . to . be . eql ( bar . name ) ;
428428 expect ( queryResult [ 0 ] ) . property ( 'email' ) . to . be . eql ( bar . email ) ;
429429 } ) ;
430+ it ( 'can execute command (select query with parenthesis) without parameters' , async function ( ) {
431+ await client . post ( '/users' ) . send ( getDummyUser ( { name : 'Foo' } ) ) ;
432+ if ( primaryDataSourceConfig . connector === 'sqlite3' ) {
433+ // Skip executing select query with bracket if datasource is sqlite
434+ // since it doesn't support it
435+ // eslint-disable-next-line @typescript-eslint/no-invalid-this
436+ this . skip ( ) ;
437+ }
438+ const queryResult = await userRepo . execute ( '(SELECT * from "user")' ) ;
439+
440+ expect ( queryResult ) . to . have . length ( 1 ) ;
441+ expect ( queryResult [ 0 ] ) . property ( 'name' ) . to . be . eql ( 'Foo' ) ;
442+ } ) ;
443+
444+ it ( 'can execute command (select query with parenthesis) using named parameters' , async function ( ) {
445+ await client . post ( '/users' ) . send ( getDummyUser ( { name : 'Foo' } ) ) ;
446+ const bar = getDummyUser ( { name : 'Bar' } ) ;
447+ await client . post ( '/users' ) . send ( bar ) ;
448+ if ( primaryDataSourceConfig . connector === 'sqlite3' ) {
449+ // Skip executing select query with bracket if datasource is sqlite
450+ // since it doesn't support it
451+ // eslint-disable-next-line @typescript-eslint/no-invalid-this
452+ this . skip ( ) ;
453+ }
454+ const queryResult = await userRepo . execute (
455+ '(SELECT * from "user" where name = $name)' ,
456+ {
457+ name : 'Bar' ,
458+ } ,
459+ ) ;
430460
461+ expect ( queryResult ) . to . have . length ( 1 ) ;
462+ expect ( queryResult [ 0 ] ) . property ( 'name' ) . to . be . eql ( bar . name ) ;
463+ expect ( queryResult [ 0 ] ) . property ( 'email' ) . to . be . eql ( bar . email ) ;
464+ } ) ;
465+ it ( 'can execute raw sql command (select query with parenthesis) using positional parameters' , async function ( ) {
466+ if ( primaryDataSourceConfig . connector === 'sqlite3' ) {
467+ // Skip executing select query with bracket if datasource is sqlite
468+ // since it doesn't support it
469+ // eslint-disable-next-line @typescript-eslint/no-invalid-this
470+ this . skip ( ) ;
471+ }
472+ await client . post ( '/users' ) . send ( getDummyUser ( { name : 'Foo' } ) ) ;
473+ const bar = getDummyUser ( { name : 'Bar' } ) ;
474+ await client . post ( '/users' ) . send ( bar ) ;
475+
476+ const queryResult = await userRepo . execute (
477+ '(SELECT * from "user" where name = $1)' ,
478+ [ 'Bar' ] ,
479+ ) ;
480+
481+ expect ( queryResult ) . to . have . length ( 1 ) ;
482+ expect ( queryResult [ 0 ] ) . property ( 'name' ) . to . be . eql ( bar . name ) ;
483+ expect ( queryResult [ 0 ] ) . property ( 'email' ) . to . be . eql ( bar . email ) ;
484+ } ) ;
431485 it ( 'can execute raw sql command (insert) using positional parameters' , async ( ) => {
432486 const user = getDummyUser ( { name : 'Foo' , active : true } ) ;
433487 if ( primaryDataSourceConfig . connector === 'sqlite3' ) {
0 commit comments