
Security News
MCP Community Begins Work on Official MCP Metaregistry
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
ruby-mysql is a MySQL client library. It is written entirely in Ruby. Therefore libmysqlclient is not required and no compilation is required during installation.
gem install ruby-mysql
require 'mysql'
my = Mysql.connect('mysql://username:password@hostname:port/dbname?charset=utf8mb4')
my.query("select col1, col2 from tblname").each do |col1, col2|
p col1, col2
end
stmt = my.prepare('insert into tblname (col1,col2) values (?,?)')
stmt.execute 123, 'abc'
MySQL type | Ruby class |
---|---|
NULL | NilClass |
INT | Integer |
DECIMAL | BigDecimal |
FLOAT, DOUBLE | Float |
DATE | Date |
DATETIME, TIMESTAMP | Time |
TIME | Float (as seconds) |
YEAR | Integer |
CHAR, VARCHAR | String |
BIT | String |
TEXT, BLOB, JSON | String |
3.0:
pp my.query('select 123,123.45,now(),cast(now() as date)').fetch.map{[_1, _1.class]}
#=> [["123", String],
# ["123.45", String],
# ["2022-11-15 00:17:11", String],
# ["2022-11-15", String]]
4.0:
pp my.query('select 123,123.45,now(),cast(now() as date)').fetch.map{[_1, _1.class]}
#=> [[123, Integer],
# [0.12345e3, BigDecimal],
# [2022-11-15 00:17:17 +0900, Time],
# [#<Date: 2022-11-15 ((2459899j,0s,0n),+0s,2299161j)>, Date]]
To specify cast: false
, you get the same behavior as in 3.0.
my.query('select 123,123.45,now(),cast(now() as date)', cast: false).fetch.map{[_1, _1.class]}
#=> [["123", String],
# ["123.45", String],
# ["2022-11-15 00:19:18", String],
# ["2022-11-15", String]]
It can also be specified during Mysql.new and Mysql.connect.
my = Mysql.connect('mysql://user:pass@localhost/', cast: false)
Changing mysql.default_options will affect the behavior of subsequently created instances.
my1 = Mysql.connect('mysql://user:pass@localhost/')
Mysql.default_options[:cast] = false
my2 = Mysql.connect('mysql://user:pass@localhost/')
pp my1.query('select 123,123.45,now(),cast(now() as date)').fetch.map{[_1, _1.class]}
#=> [[123, Integer],
# [0.12345e3, BigDecimal],
# [2022-11-15 00:26:09 +0900, Time],
# [#<Date: 2022-11-15 ((2459899j,0s,0n),+0s,2299161j)>, Date]]
pp my2.query('select 123,123.45,now(),cast(now() as date)').fetch.map{[_1, _1.class]}
#=> [["123", String],
# ["123.45", String],
# ["2022-11-15 00:26:09", String],
# ["2022-11-15", String]]
3.0:
res = my.query('select 123 union select 456')
res.entries
#=> [["123"], ["456"]]
res.entries
#=> []
4.0:
res = my.query('select 123 union select 456')
res.entries
#=> [[123], [456]]
res.entries
#=> [[123], [456]]
FAQs
Unknown package
We found that ruby-mysql demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
The MCP community is launching an official registry to standardize AI tool discovery and let agents dynamically find and install MCP servers.
Research
Security News
Socket uncovers an npm Trojan stealing crypto wallets and BullX credentials via obfuscated code and Telegram exfiltration.
Research
Security News
Malicious npm packages posing as developer tools target macOS Cursor IDE users, stealing credentials and modifying files to gain persistent backdoor access.