veeque
veeque
Explore posts from servers
DTDrizzle Team
Created by veeque on 8/30/2024 in #help
How to run a join on the result of a union
I have a union await union(...) and I would like to join it with another table. What should I do? Should I put it inside the union query itself (as monsterous as it would become)?
3 replies
DTDrizzle Team
Created by veeque on 8/28/2024 in #help
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?
3 replies