Skip to content

Commit

Permalink
Merge pull request #607 from zmariscal/feature--support-trilogy-adapter
Browse files Browse the repository at this point in the history
Feature: support trilogy adapter
  • Loading branch information
cfis authored Nov 4, 2023
2 parents f36508e + f79e913 commit 4cc0b6d
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/mariadb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
--health-timeout 5s
--health-retries 5
env:
BUNDLE_WITHOUT: "db2 oracle sqlserver sqlite postgresql"
BUNDLE_WITHOUT: "db2 oracle sqlserver sqlite postgresql trilogy"
BUNDLE_JOBS: 4
BUNDLE_PATH: vendor/bundle
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/mysql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
--health-timeout 5s
--health-retries 5
env:
BUNDLE_WITHOUT: "db2 oracle sqlserver sqlite postgresql"
BUNDLE_WITHOUT: "db2 oracle sqlserver sqlite postgresql trilogy"
BUNDLE_JOBS: 4
BUNDLE_PATH: vendor/bundle
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/postgresql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
--health-timeout 5s
--health-retries 5
env:
BUNDLE_WITHOUT: "db2 oracle sqlserver mysql splite"
BUNDLE_WITHOUT: "db2 oracle sqlserver mysql sqlite trilogy"
BUNDLE_JOBS: 4
BUNDLE_PATH: vendor/bundle
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sqlite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
ruby: [2.7, "3.0", 3.1, 3.2]
runs-on: ${{matrix.os}}
env:
BUNDLE_WITHOUT: "db2 oracle sqlserver postgresql mysql"
BUNDLE_WITHOUT: "db2 oracle sqlserver postgresql mysql trilogy"
BUNDLE_JOBS: 4
BUNDLE_PATH: vendor/bundle
steps:
Expand Down
5 changes: 5 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ group :sqlserver do
gem 'activerecord-sqlserver-adapter'
end

group :trilogy do
gem 'trilogy'
gem 'activerecord-trilogy-adapter'
end

group :test do
gem 'minitest'
end
Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Dir.glob('tasks/**/*.rake').each do |rake_file|
end

# Set up test tasks for each supported connection adapter
%w(mysql sqlite oracle oracle_enhanced postgresql ibm_db sqlserver).each do |adapter|
%w(mysql sqlite oracle oracle_enhanced postgresql ibm_db sqlserver trilogy).each do |adapter|
namespace adapter do
desc "Run tests using the #{adapter} adapter"
task "test" do
Expand Down
2 changes: 1 addition & 1 deletion lib/composite_primary_keys.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,4 @@

require_relative 'composite_primary_keys/arel/to_sql'
require_relative 'composite_primary_keys/arel/sqlserver'
require_relative 'composite_primary_keys/table_metadata'
require_relative 'composite_primary_keys/table_metadata'
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ def insert(arel, name = nil, pk = nil, id_value = nil, sequence_name = nil, bind
value = exec_insert(sql, name, binds, pk, sequence_name)

return id_value if id_value

if pk.is_a?(Array) && !value.empty?
if pk.is_a?(Array) && value.respond_to?(:empty?) && !value.empty?
# This is a CPK model and the query result is not empty. Thus we can figure out the new ids for each
# auto incremented field
pk.map {|key| value.first[key]}
Expand Down
2 changes: 2 additions & 0 deletions lib/composite_primary_keys/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ def cpk_subquery(stmt)
# database adapter to decide how to proceed.
if defined?(ActiveRecord::ConnectionAdapters::Mysql2Adapter) && connection.is_a?(ActiveRecord::ConnectionAdapters::Mysql2Adapter)
cpk_mysql_subquery(stmt)
elsif defined?(ActiveRecord::ConnectionAdapters::TrilogyAdapter) && connection.is_a?(ActiveRecord::ConnectionAdapters::TrilogyAdapter)
cpk_mysql_subquery(stmt)
elsif defined?(ActiveRecord::ConnectionAdapters::SQLServerAdapter) && connection.is_a?(ActiveRecord::ConnectionAdapters::SQLServerAdapter)
cpk_exists_subquery(stmt)
else
Expand Down
4 changes: 2 additions & 2 deletions scripts/console.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby

#
# if run as script, load the file as library while starting irb
# if run as script, load the file as library while starting irb
#
if __FILE__ == $0
irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
Expand All @@ -12,7 +12,7 @@
#
# check if the given adapter is supported (default: mysql)
#
adapters = %w[mysql sqlite oracle oracle_enhanced postgresql ibm_db]
adapters = %w[mysql sqlite oracle oracle_enhanced postgresql ibm_db trilogy]
adapter = ENV['ADAPTER'] || 'mysql'
unless adapters.include? adapter
puts "Usage: #{__FILE__} <adapter>"
Expand Down
23 changes: 23 additions & 0 deletions tasks/databases/trilogy.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace :trilogy do
task :setup do
require 'bundler'
Bundler.require(:default, :trilogy)
end

task :create_database => :setup do
Rake::Task["mysql:create_database"].invoke
end

desc 'Build the MySQL test database'
task :build_database => [:create_database] do
Rake::Task["mysql:build_database"].invoke
end

desc 'Drop the MySQL test database'
task :drop_database => :setup do
Rake::Task["mysql:drop_database"].invoke
end

desc 'Rebuild the MySQL test database'
task :rebuild_database => [:drop_database, :build_database]
end
6 changes: 6 additions & 0 deletions test/abstract_unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
puts "Loaded #{spec_name}"

# And now connect to the database
if spec_name == "trilogy"
require "activerecord-trilogy-adapter"
require "trilogy_adapter/connection"
ActiveRecord::Base.extend TrilogyAdapter::Connection
end

ActiveRecord::Base.establish_connection(spec)

# Tell active record about the configuration
Expand Down
10 changes: 10 additions & 0 deletions test/connections/databases.ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,13 @@ sqlite:
adapter: sqlite3
database: <%= File.join(project_root, 'db', 'composite_primary_keys_unittest.sqlite') %>

trilogy:
adapter: trilogy
username: github
password: github
host: 127.0.0.1
port: 3306
encoding: utf8mb4
charset: utf8mb4
collation: utf8mb4_bin
database: composite_primary_keys_unittest

0 comments on commit 4cc0b6d

Please sign in to comment.