Replies: 1 comment
-
Hey @e-e! 👋🏻 You can lock the index by using const existingRecord = await MyModel.query({ client: trx })
.forUpdate()
.where("user_id", auth.user!.id)
.whereNull("completed_at")
.first(); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm working on a React application, using Adonis v6 as the backend, with Postgres 16. In dev/strict mode, the components are mounted twice. I have a component that attempts to fetch the "active" record of a table, and if it doesn't exist, makes another request to create a new one. The table should only have one active record at a time. (the row is considered active if the
completed_at
timestamp column isNULL
). The problem I'm running into is that every time that component loads, it hits that endpoint twice, and I get two new records created. I've tried the following:and
with no luck. I'm assuming the db transaction doesn't actually lock the table. Is there a way to do this with Lucid query builder? Open to any solutions - thanks in advance.
Beta Was this translation helpful? Give feedback.
All reactions