Skip to content

Commit

Permalink
Add rbs for mysql2-0.5 (#563)
Browse files Browse the repository at this point in the history
  • Loading branch information
euglena1215 committed May 26, 2024
1 parent 23f5cfd commit b9c1383
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
22 changes: 22 additions & 0 deletions gems/mysql2/0.5/_test/test.rb
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
42 changes: 42 additions & 0 deletions gems/mysql2/0.5/client.rbs
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
20 changes: 20 additions & 0 deletions gems/mysql2/0.5/result.rbs
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

0 comments on commit b9c1383

Please sign in to comment.