File tree Expand file tree Collapse file tree 4 files changed +46
-2
lines changed Expand file tree Collapse file tree 4 files changed +46
-2
lines changed Original file line number Diff line number Diff line change @@ -246,7 +246,11 @@ class Client_AuroraDataMySQL extends Client_MySQL { // eslint-disable-line camel
246246 return method === 'first' ? rows [ 0 ] : rows ;
247247 }
248248 case 'insert' :
249- return [ getAuroraDataValue ( generatedFields [ 0 ] ) ] ;
249+ if ( generatedFields . length > 0 ) {
250+ return [ getAuroraDataValue ( generatedFields [ 0 ] ) ] ;
251+ } else {
252+ return [ undefined ] ;
253+ }
250254 case 'del' :
251255 case 'update' :
252256 case 'counter' :
Original file line number Diff line number Diff line change 11{
22 "name" : " knex-aurora-data-api-mysql" ,
3- "version" : " 2.0.4 " ,
3+ "version" : " 2.0.5 " ,
44 "description" : " Knex.js driver for MySQL AWS Aurora Data API" ,
55 "homepage" : " https://github.com/txase/knex-aurora-data-api-mysql" ,
66 "repository" : " txase/knex-aurora-data-api-mysql" ,
Original file line number Diff line number Diff line change @@ -2158,6 +2158,12 @@ module.exports = {
21582158 } ,
21592159 INSERT_RESPONSE_ROWS : [ 33 ] ,
21602160
2161+ INSERT_RESPONSE_WITHOUT_LAST_ID_DATA : {
2162+ generatedFields : [ ] ,
2163+ numberOfRecordsUpdated : 2
2164+ } ,
2165+ INSERT_RESPONSE_WITHOUT_LAST_ID_ROWS : [ undefined ] ,
2166+
21612167 UPDATE_RESPONSE_DATA : {
21622168 generatedFields : [ ] ,
21632169 numberOfRecordsUpdated : 3
Original file line number Diff line number Diff line change @@ -379,6 +379,40 @@ describe('Query statement tests', () => {
379379 expect ( inserted ) . toEqual ( constants . INSERT_RESPONSE_ROWS ) ;
380380 } ) ;
381381
382+ test ( 'Insert returns undefined primary ID when not generated' , async ( ) => {
383+ mockExecuteStatementPromise . mockResolvedValue ( constants . INSERT_RESPONSE_WITHOUT_LAST_ID_DATA ) ;
384+
385+ const inserted = await knex ( 'test' ) . insert ( [
386+ { int : 33 } ,
387+ { int : 34 }
388+ ] ) ;
389+
390+ expect ( mockExecuteStatement ) . toHaveBeenCalledTimes ( 1 ) ;
391+ expect ( mockExecuteStatement ) . toHaveBeenCalledWith ( {
392+ resourceArn : constants . AURORA_CLUSTER_ARN ,
393+ secretArn : constants . SECRET_ARN ,
394+ database : constants . DATABASE ,
395+ sql : 'insert into `test` (`int`) values (:0), (:1)' ,
396+ parameters : [
397+ {
398+ name : '0' ,
399+ value : {
400+ longValue : 33
401+ }
402+ } ,
403+ {
404+ name : '1' ,
405+ value : {
406+ longValue : 34
407+ }
408+ }
409+ ] ,
410+ includeResultMetadata : true
411+ } ) ;
412+
413+ expect ( inserted ) . toEqual ( constants . INSERT_RESPONSE_WITHOUT_LAST_ID_ROWS ) ;
414+ } ) ;
415+
382416 test ( 'Update returns number of rows updated' , async ( ) => {
383417 mockExecuteStatementPromise . mockResolvedValue ( constants . UPDATE_RESPONSE_DATA ) ;
384418
You can’t perform that action at this time.
0 commit comments