DT
Drizzle Team•12mo ago
frankscp

Transaction rolling back without error

Hello all, I'm trying to use Drizzle together with Supabase and SvelteKit to have transaction support. However, I've come across an issue which I'm having trouble understanding. The following query is successful on it's own (the value of the variables is extracted from a form data):
await db.insert(ticket).values({
ticketTypeId: ticketType,
description: description
});
await db.insert(ticket).values({
ticketTypeId: ticketType,
description: description
});
However, when I use inside a transaction, the transaction does NOT fail, but it does NOT write to the database either:
await db.transaction(async (tx) => {
await tx.insert(ticket).values({
ticketTypeId: ticketType,
description: description
});

});
await db.transaction(async (tx) => {
await tx.insert(ticket).values({
ticketTypeId: ticketType,
description: description
});

});
3 Replies
Angelelz
Angelelz•12mo ago
Seems like a bug. Two things, can you pass {logger: true} to drizzle to see what's being sent? The other, can you asign that to a variable to log it a see what's coming back?
const result = await db.insert(ticket).values({
ticketTypeId: ticketType,
description: description
});
console.log(result)
const result = await db.insert(ticket).values({
ticketTypeId: ticketType,
description: description
});
console.log(result)
And then
const result = await db.transaction(async (tx) => {
return await tx.insert(ticket).values({
ticketTypeId: ticketType,
description: description
});
});
console.log(result)
const result = await db.transaction(async (tx) => {
return await tx.insert(ticket).values({
ticketTypeId: ticketType,
description: description
});
});
console.log(result)
frankscp
frankscpOP•12mo ago
Hey, thank you for your answer I ended up stumbling upon the solution. Basically, needed to add 'prepare: false' to my drizzleClient
const client = postgres(connectionString, { prepare: false });
const client = postgres(connectionString, { prepare: false });
Angelelz
Angelelz•12mo ago
Interesting 🤔 Thanks for reporting back
Want results from more Discord servers?
Add your server