Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Adding table locking. #1076

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Adding table locking. #1076

wants to merge 1 commit into from

Conversation

jwoertink
Copy link
Member

Fixes #594

This adds some options for doing table and row locks.

AppDatabase.with_lock_on(User, mode: :row_exclusive) do
  user = UserQuery.new.id(1).for_update.first
  SaveUser.update!(user, name: "New Name")
end

Testing it in a real app, and it seems to work... I'm not sure how to test this other than just ensuring the correct SQL is generated.

Comment on lines +162 to +163
def for_update : self
@for_update = true
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Postgres supports more than just FOR UPDATE

FOR { UPDATE | NO KEY UPDATE | SHARE | KEY SHARE }

So this might need some sort of args, or maybe just different methods like

def for_no_key_update
end
def for_share
end
def for_key_share
end

# VS

def for_update(for_method)
end
for_update(:no_key_update)
for_update(:share)

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support locking tables
1 participant