Skip to content

Commit 6f7f5be

Browse files
committed
Add support for trilogy adapter
1 parent 8206409 commit 6f7f5be

File tree

7 files changed

+24
-3
lines changed

7 files changed

+24
-3
lines changed

lib/ajax-datatables-rails/datatable/column.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def formatted_value
6868
DB_ADAPTER_TYPE_CAST = {
6969
mysql: TYPE_CAST_MYSQL,
7070
mysql2: TYPE_CAST_MYSQL,
71+
trilogy: TYPE_CAST_MYSQL,
7172
sqlite: TYPE_CAST_SQLITE,
7273
sqlite3: TYPE_CAST_SQLITE,
7374
oracle: TYPE_CAST_ORACLE,

lib/ajax-datatables-rails/datatable/simple_order.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def nulls_last_sql
4747
case @adapter
4848
when :pg, :postgresql, :postgres, :oracle, :postgis
4949
'NULLS LAST'
50-
when :mysql, :mysql2, :sqlite, :sqlite3
50+
when :mysql, :mysql2, :trilogy, :sqlite, :sqlite3
5151
'IS NULL'
5252
else
5353
raise "unsupported database adapter: #{@adapter}"

spec/ajax-datatables-rails/datatable/column_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@
188188
expect(column.send(:type_cast)).to eq('CHAR')
189189
end
190190

191+
it 'returns CHAR if :db_adapter is :trilogy' do
192+
expect(datatable).to receive(:db_adapter) { :trilogy }
193+
expect(column.send(:type_cast)).to eq('CHAR')
194+
end
195+
191196
it 'returns CHAR if :db_adapter is :mysql' do
192197
expect(datatable).to receive(:db_adapter) { :mysql }
193198
expect(column.send(:type_cast)).to eq('CHAR')

spec/ajax-datatables-rails/orm/active_record_filter_records_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,16 @@
202202
)
203203
end
204204
end
205+
206+
context 'when db_adapter is trilogy' do
207+
it 'can call #to_sql on returned object' do
208+
result = datatable.build_conditions_for_selected_columns
209+
expect(result).to respond_to(:to_sql)
210+
expect(result.to_sql).to eq(
211+
"CAST(`users`.`username` AS CHAR) LIKE '%doe%' AND CAST(`users`.`email` AS CHAR) LIKE '%example%'"
212+
)
213+
end
214+
end
205215
end
206216
end
207217

spec/dummy/config/database.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ test:
1414
port: 3306
1515
username: 'root'
1616
password: 'root'
17+
<% elsif adapter == 'trilogy' %>
18+
host: '127.0.0.1'
19+
port: 3306
20+
username: 'root'
21+
password: 'root'
1722
<% elsif adapter == 'oracle_enhanced' %>
1823
host: '127.0.0.1/xe'
1924
username: <%= ENV.fetch('USER') %>

spec/spec_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def self.oracle?
7373
end
7474

7575
def self.mysql?
76-
ENV['DB_ADAPTER'] == 'mysql2'
76+
ENV['DB_ADAPTER'] == 'mysql2' || ENV['DB_ADAPTER'] == 'trilogy'
7777
end
7878

7979
def self.postgresql?

spec/support/helpers/params.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def nulls_last_sql(datatable)
7272
case datatable.db_adapter
7373
when :pg, :postgresql, :postgres, :oracle, :postgis
7474
'NULLS LAST'
75-
when :mysql, :mysql2, :sqlite, :sqlite3
75+
when :mysql, :mysql2, :trilogy, :sqlite, :sqlite3
7676
'IS NULL'
7777
else
7878
raise 'unsupported database adapter'

0 commit comments

Comments
 (0)