adding for update to a read action
I have an
after_action
block that performs a select using a read action. I'd like to turn that select into a "SELECT FOR UPDATE" - is that possible?22 Replies
Nm! The answer was to use
modify_query
on the read transaction and then use Ecto.Query.lock("FOR UPDATE")You can use
Ash.Query.lock(query, :for_update)
sorry I might be being slow here, but how do I use this within a read action block
eg.
You can use a preparation
preparations are just like
change
s from create/update/destroy actions
you can attach lifecycle hooks and things like that theregot it!
question: do you have an update action that youare passing this to?
like
get_processed_by_index -> update_it()
?
the thing you're doing isn't actually going to do what you want TBHnot quite - it is part of an action that's going to do an update, but to a different row
Ah, okay
the main thing is that if you just call this action on its own, the
transaction? true
will end
but if its called inside another transaction then it will do what you wantyup - this is in an after action block
👍
i probably didn't need the transaction? true
but it felt right to put it there 🙂
ash doesn't currently support FOR NO KEY UPDATE right? is there a way to pass that in or would that require an ash PR
IIRC if you pass a string it will use it directly in the data layer
oh perfect!
you can do this to protect yourself in the future:
is there a similar thing for
change get_and_lock("FOR NO KEY UPDATE")
I believe so, yeah
and then I'd remove the
transaction? true
just adds some protection that an action meant to set up something specific isn't called in a context where its not actually helpinggot it!
thank you!
👍 my pleasure
results in:
(i'm using postgres)
Hmm....what is your
ash_postgres
version?
i was pointing at the main branch - but forcing an update now
that was it - ty!
👍