Skip to content

Commit fe946c8

Browse files
committed
Change the NULLS_LAST SQL syntax to match the adapter type.
1 parent 6d4c90d commit fe946c8

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
it 'sql query' do
2121
expect(simple_order.query('email')).to eq(
22-
'email DESC NULLS LAST'
22+
"email DESC #{nulls_last_sql}"
2323
)
2424
end
2525
end

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
datatable.params[:order]['0'] = { column: '0', dir: 'asc' }
5555
datatable.params[:order]['1'] = { column: '1', dir: 'desc' }
5656
expect(datatable.sort_records(records).to_sql).to include(
57-
'ORDER BY users.username ASC NULLS LAST, users.email DESC NULLS LAST'
57+
"ORDER BY users.username ASC #{nulls_last_sql}, users.email DESC #{nulls_last_sql}"
5858
)
5959
end
6060
end
@@ -66,7 +66,7 @@
6666
nulls_last_datatable.params[:order]['0'] = { column: '0', dir: 'asc' }
6767
nulls_last_datatable.params[:order]['1'] = { column: '1', dir: 'desc' }
6868
expect(nulls_last_datatable.sort_records(records).to_sql).to include(
69-
'ORDER BY users.username ASC, users.email DESC NULLS LAST'
69+
"ORDER BY users.username ASC, users.email DESC #{nulls_last_sql}"
7070
)
7171
end
7272
end

spec/support/test_helpers.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,14 @@ def data
9797
end
9898
end
9999
end
100+
101+
def nulls_last_sql
102+
case AjaxDatatablesRails.config.db_adapter
103+
when -> (a) { a.in?([:pg, :postgresql, :postgres, :oracle]) }
104+
"NULLS LAST"
105+
when -> (a) { a.in?([:mysql, :mysql2, :sqlite, :sqlite3]) }
106+
"IS NULL"
107+
else
108+
raise 'unsupported database adapter'
109+
end
110+
end

0 commit comments

Comments
 (0)