tomchristensen
tomchristensen
DTDrizzle Team
Created by tomchristensen on 9/4/2023 in #help
Inconsistent transactions with Drizzle/Planetscale
I'm having issues with updating multiple records in parallel using Promise.all inside a transaction using Planetscale's serverless driver. I've created a minimal repro here: https://github.com/tomqchristensen/drizzle-ps-tx. The gist of it is that trying to update multiple records in parallel using something like this:
const updateParallelTx = async (n: number) =>
db.transaction(async (tx) => {
const promises = fooIds.map(async (id) =>
tx.update(t.foo).set({ n }).where(eq(t.foo.id, id))
);
await Promise.all(promises);
});
const updateParallelTx = async (n: number) =>
db.transaction(async (tx) => {
const promises = fooIds.map(async (id) =>
tx.update(t.foo).set({ n }).where(eq(t.foo.id, id))
);
await Promise.all(promises);
});
results in only a single record being updated and no errors thrown, i.e. the exact opposite to what one would expect from a transaction. Any ideas as to why this is the case? Happy to open an issue on GH if this is indeed a bug.
16 replies