Skip to content
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

Expose #connection_options on the Ruby binding. #48

Conversation

adrianna-chang-shopify
Copy link
Collaborator

This PR exposes a #connection_options method on the Ruby binding, allowing users to query the client for the options passed in at connect time. This is meant to be similar to Mysql2's #query_options.

We're currently using Mysql2::Client#query_options in a couple of places in our Rails apps at Shopify, and there's no equivalent in Trilogy -- we could go through the connection pool and grab the db_config instead, but it's nice to be able to access connection options on the client IMHO. It also facilitates other use cases, like being able to configure span name for MySQL instrumentation with OpenTelemetry (just as is being done for Mysql2).

As an aside: I've noticed that there are a couple of places (e.g. benchmark script, docs) where we reference a non-existent #query_options method. I'm wondering if this was removed from the API at some point? Is there any value to bringing that back in addition to #connection_options? If not, I can remove those references to avoid confusion 😄

@composerinteralia
Copy link
Contributor

I'll try to take a look at this PR early next week.

As an aside: I've noticed that there are a couple of places (e.g. benchmark script, docs) where we reference a non-existent #query_options method. I'm wondering if this was removed from the API at some point? Is there any value to bringing that back in addition to #connection_options? If not, I can remove those references to avoid confusion 😄

It looks like query_options got replaced with query_flags, replacing some rb_hash_aref in load_query_options with bit checking. From the original commit message for that change:

Use a bitfield to store the query flags instead of in a Ruby hash. This
will reduce allocations and make queries faster.

@adrianna-chang-shopify
Copy link
Collaborator Author

It looks like query_options got replaced with query_flags

Ah, thanks Daniel! I was wondering if that was maybe the case. I can cut a quick PR to update those references.

Copy link
Contributor

@composerinteralia composerinteralia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm fine with this change if it's helpful for you 👍🏻, but had one thought about discouraging folks from modifying the options via Trilogy.

contrib/ruby/lib/trilogy.rb Outdated Show resolved Hide resolved
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