Update From

Using Update From is very common in my application. I currently have to do:
const response = await dbz.execute(sql`
UPDATE "Data"
SET "deletedAt" = NOW()
FROM "Organization"
WHERE "Data"."organizationId" = "Organization"."id"
AND "Organization"."extId" = ${extId}
AND "Data"."id" = ${dataId};
`);
const response = await dbz.execute(sql`
UPDATE "Data"
SET "deletedAt" = NOW()
FROM "Organization"
WHERE "Data"."organizationId" = "Organization"."id"
AND "Organization"."extId" = ${extId}
AND "Data"."id" = ${dataId};
`);
But I want to do something like
const response = await db.update(data)
.set({ deletedAt: sql`NOW()` })
.from(organization)
.where(and(
eq(data.organizationId, organization.id),
eq(organization.extId, extId),
eq(data.id, dataId)
))
const response = await db.update(data)
.set({ deletedAt: sql`NOW()` })
.from(organization)
.where(and(
eq(data.organizationId, organization.id),
eq(organization.extId, extId),
eq(data.id, dataId)
))
I see a related issue on GitHub (https://github.com/drizzle-team/drizzle-orm/issues/208), but don't see an update since it was added to the public roadmap.
GitHub
Issues · drizzle-team/drizzle-orm
TypeScript ORM that feels like writing SQL. Contribute to drizzle-team/drizzle-orm development by creating an account on GitHub.
3 Replies
Alex.dev
Alex.dev13mo ago
Also interested in this @Dan Kochetov @Andrew Sherman any chance to get this in near future?
BaNuni
BaNuni13mo ago
me3
균어
균어13mo ago
you can use just
.set({deletedAt: new Date() OR new Date().toString()})
.set({deletedAt: new Date() OR new Date().toString()})
Want results from more Discord servers?
Add your server