-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove bool return type restriction on Avram::Database#transaction #626
Remove bool return type restriction on Avram::Database#transaction #626
Conversation
src/avram/database.cr
Outdated
@@ -156,7 +156,7 @@ abstract class Avram::Database | |||
end | |||
|
|||
# :nodoc: | |||
def transaction : Bool | |||
def transaction |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not too sure about this change. In theory, if it's ok, then we should be able to remove this line and still have things work. I pulled down this PR, and got 3 failures on SaveOperations.
@@ -156,7 +156,7 @@ abstract class Avram::Database | |||
end | |||
|
|||
# :nodoc: | |||
def transaction : Bool | |||
def transaction | |||
if current_transaction | |||
yield |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now, as a sort of "hack", we can leave the return type as Bool
, but then add a true
right after this line. The wrap_in_transaction
method will already return the bool for that branch. This lets people put whatever in the block, and we still have that return type. The reason I say "hack" though is, i'm not a huge fan of just have a random static value just chillin there, but It would be a step in the right direction, and no different than what we're doing now 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be better if this method was declared def transaction : Nil
? Anything that attempted to use the value would get a complaint. Oh, I guess Nil
is falsey.
982ba14
to
3a98b1a
Compare
Forgot about this PR but I have updated it to ignore the return value of the yield so that the block isn't forced to return a boolean. |
Fixes #416
This allows for code to use transactions like:
This would only have worked previously if
StepTwoOperation.run!
returned a boolean. Otherwisetrue
would have to be added as the last line because we required the block to return a Bool.I believe the original type restriction was put in place to match crystal-db's but it was not intention crystal-lang/crystal-db#145