Update number column with it's current value and new number

I need to convert this RAW sql query into a query in drizzle, but I can't find a way. Anyone done something similar?
UPDATE products
SET quantity = quantity + 15
WHERE id = <my-id>;
UPDATE products
SET quantity = quantity + 15
WHERE id = <my-id>;
4 Replies
stoyko
stoykoOP13mo ago
I was able to resolve this with the following query:
await ctx.db
.update(products)
.set({
quantity: sql`${products.quantity} + ${input.orderAmount}`,
})
.where(eq(products.id, productId));
await ctx.db
.update(products)
.set({
quantity: sql`${products.quantity} + ${input.orderAmount}`,
})
.where(eq(products.id, productId));
and it works great. I feel like I should be able to drop the string interpolation. But it works for now and that is fine for the moment.
Angelelz
Angelelz13mo ago
This is the way
stoyko
stoykoOP13mo ago
Do you think I can somehow get it working without using sql or will that not be possible
Angelelz
Angelelz13mo ago
This is the only way you can currently do this in drizzle
Want results from more Discord servers?
Add your server