-
-
Save xaviershay/310659 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveRecord | |
class Base | |
def atomic &block | |
transaction { | |
lock! | |
yield | |
} | |
end | |
end | |
end | |
class Sequence < ActiveRecord::Base | |
# so instead of this, | |
def nextval | |
transaction { | |
lock! | |
returning self.value += 1 do | |
save! | |
end | |
} | |
end | |
# we can do this | |
def nextval | |
atomic { | |
returning self.value += 1 do | |
save! | |
end | |
} | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment