diff --git a/src/driver/aurora-data-api/AuroraDataApiDriver.ts b/src/driver/aurora-data-api/AuroraDataApiDriver.ts index 0df90bdbd15..20619ffc46d 100644 --- a/src/driver/aurora-data-api/AuroraDataApiDriver.ts +++ b/src/driver/aurora-data-api/AuroraDataApiDriver.ts @@ -655,11 +655,13 @@ export class AuroraDataApiDriver implements Driver { /** * Creates generated map of values generated or returned by database after INSERT query. */ - createGeneratedMap(metadata: EntityMetadata, insertResult: any) { + createGeneratedMap(metadata: EntityMetadata, insertResult: any, entityIndex: number) { const generatedMap = metadata.generatedColumns.reduce((map, generatedColumn) => { let value: any; if (generatedColumn.generationStrategy === "increment" && insertResult.insertId) { - value = insertResult.insertId; + // NOTE: When multiple rows is inserted by a single INSERT statement, + // `insertId` is the value generated for the first inserted row only. + value = insertResult.insertId + entityIndex; // } else if (generatedColumn.generationStrategy === "uuid") { // console.log("getting db value:", generatedColumn.databaseName); // value = generatedColumn.getEntityValue(uuidMap); diff --git a/test/github-issues/2131/issue-2131.ts b/test/github-issues/2131/issue-2131.ts index 6d67a4aaf81..9a5accef4f7 100644 --- a/test/github-issues/2131/issue-2131.ts +++ b/test/github-issues/2131/issue-2131.ts @@ -28,7 +28,7 @@ describe("github issues > #2131 InsertResult return the same primary key", () => async () => (connections = await createTestingConnections({ entities: [__dirname + "/entity/*{.js,.ts}"], - enabledDrivers: ["sqlite", "mysql"], + enabledDrivers: ["sqlite", "mysql", "aurora-data-api"], })) ); beforeEach(() => reloadTestingDatabases(connections));