How can I use returning values when doing a `batch`?

The documentation tells you how to do batches (which are the only way to do what is essentially a transaction on D1): https://orm.drizzle.team/docs/batch-api The problem is that I have to run the following statements:
const returned = await db
.insert(schema.universities)
.values({ handle: form.data.handle })
.returning({ id: schema.universities.id });

await db.insert(schema.localizedUniversityNames).values({
university: returned[0].id,
languageTag: form.data.languageTag,
name: form.data.name,
});
const returned = await db
.insert(schema.universities)
.values({ handle: form.data.handle })
.returning({ id: schema.universities.id });

await db.insert(schema.localizedUniversityNames).values({
university: returned[0].id,
languageTag: form.data.languageTag,
name: form.data.name,
});
As you can see the second one requires the returned id from the previous one to work, and I don't see a way to do this in the batch. What can I do?
2 Replies
PyroOtter
PyroOtter4mo ago
I'm curious if this is possible as well, running into a similar issue.
Angelelz
Angelelz4mo ago
I don't think this is possible. You might need to look into creating stored procedures in your database.
Want results from more Discord servers?
Add your server