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

Merged
merged 4 commits into from
May 27, 2025

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.

Copy link
Contributor Author

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

@JuliaKovtun JuliaKovtun force-pushed the mri-transaction-wrapper branch from b9923e7 to adb274f Compare May 26, 2025 14:34
end
Copy link
Member

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.

Copy link
Contributor Author

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

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.

@klobuczek klobuczek merged commit 3fd635f into neo4jrb:5.0 May 27, 2025
9 of 15 checks passed
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