Skip to content

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

Open
wants to merge 2 commits into
base: 5.0
Choose a base branch
from

Conversation

JuliaKovtun
Copy link
Contributor

@JuliaKovtun JuliaKovtun commented May 23, 2025

Wrapper for execute_read/write (mri implementation) #251

Comment on lines +10 to +12
def run(query, **parameters)
@tx.run(query, **parameters)
end
Copy link
Member

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)) }))
Copy link
Member

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,

Suggested change
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:

Suggested change
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.

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

Successfully merging this pull request may close these issues.

2 participants