James
James
Explore posts from servers
DTDrizzle Team
Created by James on 10/11/2024 in #help
$returningId returning extra rows
Using a workaround until this is fixed:
export function getInsertedIds([
{ affectedRows, insertId },
]: MySqlRawQueryResult) {
return Array.from(
{ length: affectedRows },
(_, i) => BigInt(insertId) + BigInt(i)
);
}
export function getInsertedIds([
{ affectedRows, insertId },
]: MySqlRawQueryResult) {
return Array.from(
{ length: affectedRows },
(_, i) => BigInt(insertId) + BigInt(i)
);
}
Usage:
await db.insert(table).values([row1, row2]).then(getInsertedIds)
await db.insert(table).values([row1, row2]).then(getInsertedIds)
3 replies
DTDrizzle Team
Created by James on 10/11/2024 in #help
$returningId returning extra rows
It happens when there is a secondary unique id on the table, in my case I have a publicId field:
char({
length: NANO_ID_LENGTH,
})
.notNull()
.unique()
.$defaultFn(generateNanoId)
char({
length: NANO_ID_LENGTH,
})
.notNull()
.unique()
.$defaultFn(generateNanoId)
3 replies