Is there a way to limit update to just 1 document?

I know there will be multiple documents matching this where query, but I only want to update 1 of them at a time.
export const joinTable = async (tableId: number, seatedPlayerId: number) => {
await db
.update(tableSeats)
.set({ seatedPlayerId })
.where(and(eq(tableSeats.tableId, tableId), isNull(tableSeats.seatedPlayerId)));
};
export const joinTable = async (tableId: number, seatedPlayerId: number) => {
await db
.update(tableSeats)
.set({ seatedPlayerId })
.where(and(eq(tableSeats.tableId, tableId), isNull(tableSeats.seatedPlayerId)));
};
Any ideas on how I would accomplish that? I feel like limit should potentially be an option on update
4 Replies
json
json3mo ago
+1 on this
Shashank
Shashank3mo ago
as long as your tableId is unique it will only happen at that one document
DoggeSlapper
DoggeSlapper3mo ago
Use a subquery or make sure ur where caliuse just resturn 1 record
Mario564
Mario5643mo ago
(Copy and pasted from another thread) There's a PR that will implement limit in delete and update in MySQL and SQLite. This will be merged after this upcoming release
Want results from more Discord servers?
Add your server