jonpage
jonpage
DTDrizzle Team
Created by jonpage on 12/1/2023 in #help
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.
5 replies