From 6f7f5be84f55c8af1d978a6296742d96e7f0faa2 Mon Sep 17 00:00:00 2001 From: Mrudul Tarwatkar Date: Thu, 8 Feb 2024 09:07:44 +0000 Subject: [PATCH 1/4] Add support for trilogy adapter --- lib/ajax-datatables-rails/datatable/column.rb | 1 + lib/ajax-datatables-rails/datatable/simple_order.rb | 2 +- spec/ajax-datatables-rails/datatable/column_spec.rb | 5 +++++ .../orm/active_record_filter_records_spec.rb | 10 ++++++++++ spec/dummy/config/database.yml | 5 +++++ spec/spec_helper.rb | 2 +- spec/support/helpers/params.rb | 2 +- 7 files changed, 24 insertions(+), 3 deletions(-) diff --git a/lib/ajax-datatables-rails/datatable/column.rb b/lib/ajax-datatables-rails/datatable/column.rb index 1c169d2..747e546 100644 --- a/lib/ajax-datatables-rails/datatable/column.rb +++ b/lib/ajax-datatables-rails/datatable/column.rb @@ -68,6 +68,7 @@ def formatted_value DB_ADAPTER_TYPE_CAST = { mysql: TYPE_CAST_MYSQL, mysql2: TYPE_CAST_MYSQL, + trilogy: TYPE_CAST_MYSQL, sqlite: TYPE_CAST_SQLITE, sqlite3: TYPE_CAST_SQLITE, oracle: TYPE_CAST_ORACLE, diff --git a/lib/ajax-datatables-rails/datatable/simple_order.rb b/lib/ajax-datatables-rails/datatable/simple_order.rb index 840a7a9..b7824b6 100644 --- a/lib/ajax-datatables-rails/datatable/simple_order.rb +++ b/lib/ajax-datatables-rails/datatable/simple_order.rb @@ -47,7 +47,7 @@ def nulls_last_sql case @adapter when :pg, :postgresql, :postgres, :oracle, :postgis 'NULLS LAST' - when :mysql, :mysql2, :sqlite, :sqlite3 + when :mysql, :mysql2, :trilogy, :sqlite, :sqlite3 'IS NULL' else raise "unsupported database adapter: #{@adapter}" diff --git a/spec/ajax-datatables-rails/datatable/column_spec.rb b/spec/ajax-datatables-rails/datatable/column_spec.rb index ec3409d..772694a 100644 --- a/spec/ajax-datatables-rails/datatable/column_spec.rb +++ b/spec/ajax-datatables-rails/datatable/column_spec.rb @@ -188,6 +188,11 @@ expect(column.send(:type_cast)).to eq('CHAR') end + it 'returns CHAR if :db_adapter is :trilogy' do + expect(datatable).to receive(:db_adapter) { :trilogy } + expect(column.send(:type_cast)).to eq('CHAR') + end + it 'returns CHAR if :db_adapter is :mysql' do expect(datatable).to receive(:db_adapter) { :mysql } expect(column.send(:type_cast)).to eq('CHAR') diff --git a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb index 1dd108a..6ee96bb 100644 --- a/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb +++ b/spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb @@ -202,6 +202,16 @@ ) end end + + context 'when db_adapter is trilogy' do + it 'can call #to_sql on returned object' do + result = datatable.build_conditions_for_selected_columns + expect(result).to respond_to(:to_sql) + expect(result.to_sql).to eq( + "CAST(`users`.`username` AS CHAR) LIKE '%doe%' AND CAST(`users`.`email` AS CHAR) LIKE '%example%'" + ) + end + end end end diff --git a/spec/dummy/config/database.yml b/spec/dummy/config/database.yml index 949cea8..a879c29 100644 --- a/spec/dummy/config/database.yml +++ b/spec/dummy/config/database.yml @@ -14,6 +14,11 @@ test: port: 3306 username: 'root' password: 'root' +<% elsif adapter == 'trilogy' %> + host: '127.0.0.1' + port: 3306 + username: 'root' + password: 'root' <% elsif adapter == 'oracle_enhanced' %> host: '127.0.0.1/xe' username: <%= ENV.fetch('USER') %> diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d042015..9ecc3ef 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -73,7 +73,7 @@ def self.oracle? end def self.mysql? - ENV['DB_ADAPTER'] == 'mysql2' + ENV['DB_ADAPTER'] == 'mysql2' || ENV['DB_ADAPTER'] == 'trilogy' end def self.postgresql? diff --git a/spec/support/helpers/params.rb b/spec/support/helpers/params.rb index 0d85bb2..406b038 100644 --- a/spec/support/helpers/params.rb +++ b/spec/support/helpers/params.rb @@ -72,7 +72,7 @@ def nulls_last_sql(datatable) case datatable.db_adapter when :pg, :postgresql, :postgres, :oracle, :postgis 'NULLS LAST' - when :mysql, :mysql2, :sqlite, :sqlite3 + when :mysql, :mysql2, :trilogy, :sqlite, :sqlite3 'IS NULL' else raise 'unsupported database adapter' From 1739989ed780023d4abd95413184cae7caae2149 Mon Sep 17 00:00:00 2001 From: Mrudul Tarwatkar Date: Thu, 8 Feb 2024 10:30:25 +0000 Subject: [PATCH 2/4] Install trilogy adapter for rails <= 7.0 --- .github/workflows/ci.yml | 3 ++- appraisal.yml | 9 +++++++++ gemfiles/rails_6.0.6.gemfile | 4 ++++ gemfiles/rails_6.1.7.gemfile | 4 ++++ gemfiles/rails_7.0.8.gemfile | 4 ++++ 5 files changed, 23 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b04e7e6..9fa05f9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -66,6 +66,7 @@ jobs: - sqlite3 - postgresql - mysql2 + - trilogy - oracle_enhanced steps: @@ -85,7 +86,7 @@ jobs: # See: https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-README.md#mysql run: | - if [ "${DB_ADAPTER}" = "mysql2" ]; then + if [ "${DB_ADAPTER}" = "mysql2" ] || [ "${DB_ADAPTER}" = "trilogy" ]; then sudo systemctl start mysql.service mysql -u root -proot -e 'create database ajax_datatables_rails;' fi diff --git a/appraisal.yml b/appraisal.yml index e5de3f2..3e31e0b 100644 --- a/appraisal.yml +++ b/appraisal.yml @@ -6,6 +6,9 @@ mysql2: version: '' install_if: '-> { ENV["DB_ADAPTER"] == "mysql2" }' + activerecord-trilogy-adapter: + version: '' + install_if: '-> { ENV["DB_ADAPTER"] == "trilogy" }' activerecord-oracle_enhanced-adapter: version: ~> 6.0.0 install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' @@ -23,6 +26,9 @@ mysql2: version: '' install_if: '-> { ENV["DB_ADAPTER"] == "mysql2" }' + activerecord-trilogy-adapter: + version: '' + install_if: '-> { ENV["DB_ADAPTER"] == "trilogy" }' activerecord-oracle_enhanced-adapter: version: ~> 6.1.0 install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' @@ -40,6 +46,9 @@ mysql2: version: '' install_if: '-> { ENV["DB_ADAPTER"] == "mysql2" }' + activerecord-trilogy-adapter: + version: '' + install_if: '-> { ENV["DB_ADAPTER"] == "trilogy" }' activerecord-oracle_enhanced-adapter: version: ~> 7.0.0 install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' diff --git a/gemfiles/rails_6.0.6.gemfile b/gemfiles/rails_6.0.6.gemfile index 7149371..4fd11c2 100644 --- a/gemfiles/rails_6.0.6.gemfile +++ b/gemfiles/rails_6.0.6.gemfile @@ -13,6 +13,10 @@ install_if -> { ENV["DB_ADAPTER"] == "mysql2" } do gem "mysql2" end +install_if -> { ENV["DB_ADAPTER"] == "trilogy" } do + gem "activerecord-trilogy-adapter" +end + install_if -> { ENV["DB_ADAPTER"] == "oracle_enhanced" } do gem "activerecord-oracle_enhanced-adapter", "~> 6.0.0" gem "ruby-oci8" diff --git a/gemfiles/rails_6.1.7.gemfile b/gemfiles/rails_6.1.7.gemfile index 39ab3aa..339cbe4 100644 --- a/gemfiles/rails_6.1.7.gemfile +++ b/gemfiles/rails_6.1.7.gemfile @@ -13,6 +13,10 @@ install_if -> { ENV["DB_ADAPTER"] == "mysql2" } do gem "mysql2" end +install_if -> { ENV["DB_ADAPTER"] == "trilogy" } do + gem "activerecord-trilogy-adapter" +end + install_if -> { ENV["DB_ADAPTER"] == "oracle_enhanced" } do gem "activerecord-oracle_enhanced-adapter", "~> 6.1.0" gem "ruby-oci8" diff --git a/gemfiles/rails_7.0.8.gemfile b/gemfiles/rails_7.0.8.gemfile index 8f02aeb..2fa3b03 100644 --- a/gemfiles/rails_7.0.8.gemfile +++ b/gemfiles/rails_7.0.8.gemfile @@ -13,6 +13,10 @@ install_if -> { ENV["DB_ADAPTER"] == "mysql2" } do gem "mysql2" end +install_if -> { ENV["DB_ADAPTER"] == "trilogy" } do + gem "activerecord-trilogy-adapter" +end + install_if -> { ENV["DB_ADAPTER"] == "oracle_enhanced" } do gem "activerecord-oracle_enhanced-adapter", "~> 7.0.0" gem "ruby-oci8" From e27ba3f82d755e6b4132c0911a61da38a54bd756 Mon Sep 17 00:00:00 2001 From: Mrudul Tarwatkar Date: Thu, 8 Feb 2024 23:46:02 +0530 Subject: [PATCH 3/4] Added trilogy gem for Rails 7.1 --- appraisal.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/appraisal.yml b/appraisal.yml index 3e31e0b..fbc476a 100644 --- a/appraisal.yml +++ b/appraisal.yml @@ -66,6 +66,9 @@ mysql2: version: '' install_if: '-> { ENV["DB_ADAPTER"] == "mysql2" }' + activerecord-trilogy-adapter: + version: '' + install_if: '-> { ENV["DB_ADAPTER"] == "trilogy" }' # activerecord-oracle_enhanced-adapter: # version: ~> 7.0.0 # install_if: '-> { ENV["DB_ADAPTER"] == "oracle_enhanced" }' From 78a6760fa75b800e2342acbc9cad15ffe844b6e5 Mon Sep 17 00:00:00 2001 From: Mrudul Tarwatkar Date: Thu, 8 Feb 2024 23:52:41 +0530 Subject: [PATCH 4/4] Add dependency in 7.1 gemfile --- gemfiles/rails_7.1.0.gemfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gemfiles/rails_7.1.0.gemfile b/gemfiles/rails_7.1.0.gemfile index 4f58f57..3a5bd4a 100644 --- a/gemfiles/rails_7.1.0.gemfile +++ b/gemfiles/rails_7.1.0.gemfile @@ -13,6 +13,10 @@ install_if -> { ENV["DB_ADAPTER"] == "mysql2" } do gem "mysql2" end +install_if -> { ENV["DB_ADAPTER"] == "trilogy" } do + gem "activerecord-trilogy-adapter" +end + install_if -> { ENV["DB_ADAPTER"] == "postgis" } do gem "activerecord-postgis-adapter" end