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

Add rbs for mysql2-0.5 #563

Merged
merged 1 commit into from
May 26, 2024
Merged

Add rbs for mysql2-0.5 #563

merged 1 commit into from
May 26, 2024

Conversation

euglena1215
Copy link
Contributor

Copy link

@euglena1215 Thanks for your contribution!

Please follow the instructions below for each change.
See also: https://github.com/ruby/gem_rbs_collection/blob/main/docs/CONTRIBUTING.md

Available commands

You can use the following commands by commenting on this PR.

  • /merge: Merge this PR if CI passes

mysql2

This RBS files are newly added.

You can merge this PR immediately if the CI passes.
Just comment /merge to merge this PR.

@euglena1215
Copy link
Contributor Author

/merge

@github-actions github-actions bot merged commit b9c1383 into ruby:main May 26, 2024
4 checks passed
@euglena1215 euglena1215 deleted the mysql2 branch May 26, 2024 02:52
# and performance_schema.session_account_connect_attrs
def parse_connect_attrs: (untyped conn_attrs) -> (::Hash[untyped, untyped] | untyped)

def query: (String sql, ?::Hash[untyped, untyped] options) -> Mysql2::result
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The query method changes the type returned by the as keyword argument.
If as: :hash or unspecified, it returns Array[Hash]; if as: :array, it returns Array[Array].

If RBS could distinguish and overload literals rather than the type of the argument value, it should be able to uniquely determine the type.

def query: (String sql) -> Mysql2::ResultAsHash
         | (String sql, as: :hash) -> Mysql2::ResultAsHash
         | (String sql, as: :array) -> Mysql2::ResultAsArray

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The above RBS syntax was found to work correctly. I was mistaken.

On the other hand, the query method was implemented to override the options passed in initialize, so the query method argument did not uniquely determine the type of the return value...

Mysql2::Client.new.query(“SELECT * FROM users”) # => Array[Hash].
Mysql2::Client.new(as: :array).query(“SELECT * FROM users”) # => maybe it should be Array[Array] 

Copy link

Thanks for your review, @euglena1215!

@euglena1215, @euglena1215 This PR is ready to be merged.
Just comment /merge to merge this PR.

1 similar comment
Copy link

Thanks for your review, @euglena1215!

@euglena1215, @euglena1215 This PR is ready to be merged.
Just comment /merge to merge this PR.

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

Successfully merging this pull request may close these issues.

None yet

1 participant