trilogy-libraries / trilogy

Trilogy is a client library for MySQL-compatible database servers, designed for performance, flexibility, and ease of embedding.
MIT License
698 stars 69 forks source link

Switching from `mysql2` to `trilogy` in Rails #1

Closed Kareem-Emad closed 2 years ago

Kareem-Emad commented 2 years ago

I'm trying to integrate trilogy in a toy project I was working on with mysql2 without doing a lot of changes. Since I was using ActiveRecord to write my queries, I thought it would be nice if we could simply replace the adapter attrribute in config/database,yml from mysql2 to be trilogy, but it didn't work

.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require': Could not load the 'trilogy' Active Record adapter. Ensure that the adapter is spelled correctly in config/database.yml and that you've added the necessary adapter gem to your Gemfile. (LoadError)

So I was wondering if there is a way to add trilogy as an ActiveRecord adapter or if such feature could be supported in the future?

Process

  1. Create a new Rails project (Rails 5, ruby 2.5, mysql2 gem)
  2. Created a few DB models to test with using rails g model.
  3. Added trilogy gem to the gemfile and updated Gemlock bundle update.
  4. Updated adapter attribute in config/database.yml to be trilogy instead of mysql2.
  5. Ran rails c

Expected result

Running Rails c should work and I can run MyModelName.connection successfully.

Current result

Rails console fails to start

.rbenv/versions/2.5.8/lib/ruby/gems/2.5.0/gems/bootsnap-1.7.3/lib/bootsnap/load_path_cache/core_ext/kernel_require.rb:23:in `require': Could not load the 'trilogy' Active Record adapter. Ensure that the adapter is spelled correctly in config/database.yml and that you've added the necessary adapter gem to your Gemfile. (LoadError)
matthewd commented 2 years ago

Hi, and thanks for the interest!

We do indeed have an Active Record adapter that we'll soon be open-sourcing as a separate project -- we just had to get this low-level library out first. (But note it's likely to require Rails 7.0+ -- older Rails versions are progressively less likely to be supported.)

dfuentes77 commented 2 years ago

Is this adapter out yet? Is this all a drop in replacement for mysql2? Does it require Rails7? I searched a bit and couldn't find anything obvious on any of this. Thanks!

composerinteralia commented 2 years ago

The adapter is not out yet, but we are working on it. It currently only supports Rails 7.0+. Trilogy is also still missing some things, like support for prepared statements.

antarr commented 9 months ago

I'm having the same problem on a Rails 7 project

bensheldon commented 9 months ago