-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
23f5cfd
commit b9c1383
Showing
3 changed files
with
84 additions
and
0 deletions.
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 |