-
Notifications
You must be signed in to change notification settings - Fork 29
Wrapper for execute_read/write transaction #256
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
Conversation
def run(query, **parameters) | ||
@tx.run(query, **parameters) | ||
end |
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.
Use delegate :run, to: :@tx
at the top of the class definition
@@ -48,11 +48,11 @@ def write_transaction(**config, &block) | |||
end | |||
|
|||
def execute_read(**config, &block) | |||
transaction(AccessMode::READ, **config, &block) | |||
transaction(AccessMode::READ, **config, &(->(tx) { block.call(DelegatingTransaction.new(tx)) })) |
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.
We have a nicer more idiomatic syntax for that,
transaction(AccessMode::READ, **config, &(->(tx) { block.call(DelegatingTransaction.new(tx)) })) | |
transaction(AccessMode::READ, **config) { block.call(DelegatingTransaction.new(it)) } |
Alternatively composition, bonus points for investigation. Personally never used it before:
transaction(AccessMode::READ, **config, &(->(tx) { block.call(DelegatingTransaction.new(tx)) })) | |
transaction(AccessMode::READ, **config, &(DelegatingTransaction.method(:new) >> block)) |
Looking at it I don't think it beats the former basic ruby syntax.
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.
I went with the first option - it's simple and readable. I also tested the second (with >>), and it works well too, thanks for the suggestions
b9923e7
to
adb274f
Compare
end |
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.
I think we want the final new line character. It has been suggested by rubocop and we have been following it sine then.
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.
Yes, makes sense - I added the final new line, which removed the warning. GitHub just doesn't show it in the diff.
end | ||
|
||
def execute_write(**config, &block) | ||
transaction(AccessMode::WRITE, **config, &block) | ||
transaction(AccessMode::WRITE, **config) { |tx| block.call(DelegatingTransaction.new(tx)) } |
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 that it has been simplified, it becomes more obvious that the duplication needs to be fixed.
Introduce a parameter in transaction
method or maybe better a private delegating_transaction
method which delegates to transaction
with modified block.
Wrapper for execute_read/write (mri implementation) #251