Browse Source

[ruby/rack-sequel] Use trilogy for the MySQL adapter (#10072)

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
Petrik de Heus 1 week ago
parent
commit
b79f8ba005

+ 1 - 1
frameworks/Ruby/rack-sequel/Gemfile

@@ -5,7 +5,7 @@ gem 'sequel', '~> 5.0'
 gem 'rack', '~> 3.1'
 
 group :mysql, optional: true do
-  gem 'mysql2', '~> 0.4', platforms: [:ruby, :windows]
+  gem 'trilogy', '~> 2.9', platforms: [:ruby, :windows]
 end
 
 group :postgresql, optional: true do

+ 2 - 2
frameworks/Ruby/rack-sequel/Gemfile.lock

@@ -3,7 +3,6 @@ GEM
   specs:
     bigdecimal (3.1.9)
     json (2.13.2)
-    mysql2 (0.5.6)
     nio4r (2.7.4)
     pg (1.5.9)
     puma (6.6.0)
@@ -14,6 +13,7 @@ GEM
     sequel_pg (1.17.1)
       pg (>= 0.18.0, != 1.2.0)
       sequel (>= 4.38.0)
+    trilogy (2.9.0)
 
 PLATFORMS
   ruby
@@ -22,12 +22,12 @@ PLATFORMS
 
 DEPENDENCIES
   json (~> 2.8)
-  mysql2 (~> 0.4)
   pg (~> 1.5)
   puma (~> 6.5)
   rack (~> 3.1)
   sequel (~> 5.0)
   sequel_pg (~> 1.6)
+  trilogy (~> 2.9)
 
 BUNDLED WITH
    2.7.0

+ 10 - 6
frameworks/Ruby/rack-sequel/boot.rb

@@ -8,13 +8,17 @@ Bundler.require(:default) # Load core modules
 def connect(dbtype)
   Bundler.require(dbtype) # Load database-specific modules
 
-  adapters = {
-    mysql: 'mysql2',
-    postgresql: 'postgres'
-  }
-
   opts = {}
 
+  if dbtype == :mysql
+    adapter = 'trilogy'
+    opts[:ssl] = true
+    opts[:ssl_mode] = 4 # Trilogy::SSL_PREFERRED_NOVERIFY
+    opts[:tls_min_version] = 3 # Trilogy::TLS_VERSION_12
+  else
+    adapter = 'postgresql'
+  end
+
   # Determine threading/thread pool size and timeout
   if defined?(Puma) && (threads = Puma.cli_config.options.fetch(:max_threads)) > 1
     opts[:max_connections] = (2 * Math.log(threads)).floor
@@ -23,7 +27,7 @@ def connect(dbtype)
 
   Sequel.connect \
     '%{adapter}://%{host}/%{database}?user=%{user}&password=%{password}' % {
-      adapter: (dbtype == :mysql ? 'mysql2' : 'postgresql'),
+      adapter: adapter,
       host: 'tfb-database',
       database: 'hello_world',
       user: 'benchmarkdbuser',