Skip to content

Commit

Permalink
fix: (aurora-data-api) get correct increment primary key for multiple…
Browse files Browse the repository at this point in the history
… entities inserted

Closes: typeorm#7385
  • Loading branch information
coyoteecd committed Feb 18, 2021
1 parent 142a6ac commit a00e130
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/driver/aurora-data-api/AuroraDataApiDriver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/github-issues/2131/issue-2131.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit a00e130

Please sign in to comment.