K
Kysely13mo ago
bun

How to return last inserted ID ?

export async function createCommands(deviceId: number, commands: string[]) {
return db
.insertInto("commands")
.values(commands.map((c) => ({ deviceId, content: c })))
.returning("id")
.executeTakeFirstOrThrow()
}
export async function createCommands(deviceId: number, commands: string[]) {
return db
.insertInto("commands")
.values(commands.map((c) => ({ deviceId, content: c })))
.returning("id")
.executeTakeFirstOrThrow()
}
For this example, how do I only return the last inserted ID ?
3 Replies
koskimas
koskimas13mo ago
Did you try reading the documentation?
bun
bun13mo ago
yes, many times, didn't find anything specifically regarding last inserted id @koskimas i understood that by default postgres doesn't do that but how do i make it do that ?
Want results from more Discord servers?
Add your server