Skip to content

Commit ac10006

Browse files
authored
[ruby/sinatra] Use trilogy for the MySQL adapter (#8471) (#10067)
Trilogy is a new client library for MySQL-compatible database servers, designed for performance, flexibility, and ease of embedding. It is used by Github and Shopify in production and will probably replace the `mysql2` library. https://github.com/trilogy-libraries/trilogy
1 parent 095c7de commit ac10006

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

frameworks/Ruby/sinatra/Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ gem 'json', '~> 2.8'
55
gem 'sinatra', '~> 4.0', require: 'sinatra/base'
66

77
group :mysql, optional: true do
8-
gem 'mysql2', '~> 0.5', :platforms=>[:ruby, :windows]
8+
gem 'trilogy', '~> 2.9.0', platforms: [:ruby, :windows]
99
end
1010

1111
group :postgresql, optional: true do

frameworks/Ruby/sinatra/Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ GEM
3434
minitest (5.25.5)
3535
mustermann (3.0.3)
3636
ruby2_keywords (~> 0.0.1)
37-
mysql2 (0.5.6)
3837
nio4r (2.7.4)
3938
pg (1.5.9)
4039
puma (6.6.0)
@@ -58,6 +57,7 @@ GEM
5857
tilt (~> 2.0)
5958
tilt (2.6.0)
6059
timeout (0.4.3)
60+
trilogy (2.9.0)
6161
tzinfo (2.0.6)
6262
concurrent-ruby (~> 1.0)
6363
uri (1.0.3)
@@ -71,10 +71,10 @@ DEPENDENCIES
7171
activerecord (~> 8.0)
7272
iodine (~> 0.7)
7373
json (~> 2.8)
74-
mysql2 (~> 0.5)
7574
pg (~> 1.5)
7675
puma (~> 6.4)
7776
sinatra (~> 4.0)
77+
trilogy (~> 2.9.0)
7878

7979
BUNDLED WITH
8080
2.7.0

frameworks/Ruby/sinatra/boot.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,22 @@ def connect(dbtype)
1515
Bundler.require(dbtype) # Load database-specific modules
1616

1717
opts = {
18-
adapter: (dbtype == :mysql ? 'mysql2' : 'postgresql'),
1918
username: 'benchmarkdbuser',
2019
password: 'benchmarkdbpass',
2120
host: 'tfb-database',
2221
database: 'hello_world'
2322
}
2423

24+
if dbtype == :mysql
25+
opts[:adapter] = 'trilogy'
26+
opts[:ssl] = true
27+
opts[:ssl_mode] = 4 # Trilogy::SSL_PREFERRED_NOVERIFY
28+
opts[:tls_min_version] = 3 # Trilogy::TLS_VERSION_12
29+
else
30+
opts[:adapter] = 'postgresql'
31+
end
32+
33+
2534
# Determine threading/thread pool size and timeout
2635
if defined?(Puma) && (threads = Puma.cli_config.options.fetch(:max_threads)) > 1
2736
opts[:pool] = (2 * Math.log(threads)).floor
@@ -44,7 +53,7 @@ class World < ActiveRecord::Base
4453
alias_attribute(:randomNumber, :randomnumber) \
4554
if connection.adapter_name.downcase.start_with?('postgres')
4655

47-
if connection.adapter_name.downcase.start_with?('mysql')
56+
if connection.adapter_name.downcase.start_with?('trilogy')
4857
def self.upsert_all(attributes, on_duplicate: :update, update_only: nil, returning: nil, unique_by: nil, record_timestamps: nil)
4958
# On MySQL Batch updates verification isn't supported yet by TechEmpower.
5059
# https://github.com/TechEmpower/FrameworkBenchmarks/issues/5983

0 commit comments

Comments
 (0)