-
Notifications
You must be signed in to change notification settings - Fork 112
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
+84
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
require "mysql2" | ||
|
||
client = Mysql2::Client.new( | ||
host: '127.0.0.1', | ||
port: 3306, | ||
username: 'root', | ||
password: 'password', | ||
database: 'foo', | ||
symbolize_keys: true, | ||
cast_booleans: true, | ||
reconnect: true, | ||
) | ||
|
||
client.query("SELECT * FROM users").each do |row| | ||
raise unless row.is_a?(Hash) | ||
row[:id] | ||
end | ||
|
||
client.query("SELECT id FROM users", as: :array).each do |row| | ||
raise unless row.is_a?(Array) | ||
row[0] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
module Mysql2 | ||
class Client | ||
self.@default_query_options: untyped | ||
|
||
@read_timeout: untyped | ||
|
||
@query_options: untyped | ||
|
||
attr_reader query_options: untyped | ||
|
||
attr_reader read_timeout: untyped | ||
|
||
def self.default_query_options: () -> untyped | ||
|
||
def initialize: (Hash[(String | Symbol), untyped] opts) -> void | ||
|
||
def parse_ssl_mode: (untyped mode) -> untyped | ||
|
||
def parse_flags_array: (untyped flags, ?::Integer initial) -> untyped | ||
|
||
# Find any default system CA paths to handle system roots | ||
# by default if stricter validation is requested and no | ||
# path is provide. | ||
def find_default_ca_path: () -> untyped | ||
|
||
# Set default program_name in performance_schema.session_connect_attrs | ||
# 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 | ||
|
||
def query_info: () -> (::Hash[untyped, untyped] | untyped) | ||
|
||
def info: () -> untyped | ||
|
||
def last_id: () -> Integer | ||
|
||
private | ||
|
||
def self.local_offset: () -> untyped | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Mysql2 | ||
type row_value_type = String | Integer | nil | ||
type result = ResultAsHash | ResultAsArray | ||
|
||
class ResultAsHash | ||
attr_reader server_flags: untyped | ||
|
||
include Enumerable[Hash[Symbol, row_value_type]] | ||
|
||
def each: () { (Hash[Symbol, row_value_type]) -> void } -> void | ||
end | ||
|
||
class ResultAsArray | ||
attr_reader server_flags: untyped | ||
|
||
include Enumerable[Array[row_value_type]] | ||
|
||
def each: () { (Array[row_value_type]) -> void } -> void | ||
end | ||
end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The
query
method changes the type returned by theas
keyword argument.If
as: :hash
or unspecified, it returnsArray[Hash]
; ifas: :array
, it returnsArray[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.
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.
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 ininitialize
, so thequery
method argument did not uniquely determine the type of the return value...