In SvelteKit I'm using Drizzle ORM ```ts db.transaction(async (tx) => { const returned = await tx

In SvelteKit I'm using Drizzle ORM

db.transaction(async (tx) => {
  const returned = await tx
    .insert(schema.universities)
    .values({ handle: form.data.handle })
    .returning({ id: schema.universities.id });

  await tx.insert(schema.localizedUniversityNames).values({
    university: returned[0].id,
    languageTag: form.data.languageTag,
    name: form.data.name,
  });
});


This code doesn't work, but doing it without a transaction (remove the wrapper and use db rather than tx does.

This is the error I'm getting in dev:

To execute a transaction, please use the state.storage.transaction() API instead of the SQL BEGIN TRANSACTION or SAVEPOINT statements. The JavaScript API is safer because it will automatically roll back on exceptions, and because it interacts correctly with Durable Objects' automatic atomic write coalescing.


How do I go about using this JS API? 😅
Was this page helpful?