Skip to content

Commit

Permalink
fixing the primary key insert
Browse files Browse the repository at this point in the history
  • Loading branch information
invisal committed May 3, 2024
1 parent 44e50e2 commit 8a9ed6a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions gui/src/drivers/base-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ interface DatabaseTableOperationInsert {
operation: "INSERT";
values: Record<string, DatabaseValue>;
autoIncrementPkColumn?: string;
pk?: string[];
}

interface DatabaseTableOperationUpdate {
Expand Down
20 changes: 18 additions & 2 deletions gui/src/drivers/sqlite-base-driver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,25 @@ export abstract class SqliteLikeBaseDriver extends BaseDriver {
record: selectResult.rows[0],
lastId: r.lastInsertRowid,
});
}
} else if (op.pk && op.pk.length > 0) {
const selectStatement = generateSelectOneWithConditionStatement(
tableName,
op.pk.reduce<Record<string, unknown>>((a, b) => {
a[b] = op.values[b];
return a;
}, {})
);

tmp.push({});
// This transform to make it friendly for sending via HTTP
const selectResult = await this.query(selectStatement);

tmp.push({
record: selectResult.rows[0],
lastId: r.lastInsertRowid,
});
} else {
tmp.push({});
}
}

tmp.push({});
Expand Down
1 change: 1 addition & 0 deletions gui/src/lib/sql-execute-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function generateTableChangePlan({
autoIncrementPkColumn: tableSchema.autoIncrement
? tableSchema.pk[0]
: undefined,
pk: tableSchema.pk,
},
});
} else if (row.isRemoved) {
Expand Down

0 comments on commit 8a9ed6a

Please sign in to comment.