@@ -41,17 +41,29 @@ def sort_nulls_last?
4141 column . nulls_last? || @nulls_last == true
4242 end
4343
44+ PG_NULL_STYLE = 'NULLS LAST'
45+ MYSQL_NULL_STYLE = 'IS NULL'
46+ private_constant :PG_NULL_STYLE
47+ private_constant :MYSQL_NULL_STYLE
48+
49+ NULL_STYLE_MAP = {
50+ pg : PG_NULL_STYLE ,
51+ postgresql : PG_NULL_STYLE ,
52+ postgres : PG_NULL_STYLE ,
53+ postgis : PG_NULL_STYLE ,
54+ oracle : PG_NULL_STYLE ,
55+ mysql : MYSQL_NULL_STYLE ,
56+ mysql2 : MYSQL_NULL_STYLE ,
57+ trilogy : MYSQL_NULL_STYLE ,
58+ sqlite : MYSQL_NULL_STYLE ,
59+ sqlite3 : MYSQL_NULL_STYLE ,
60+ } . freeze
61+ private_constant :NULL_STYLE_MAP
62+
4463 def nulls_last_sql
4564 return unless sort_nulls_last?
4665
47- case @adapter
48- when :pg , :postgresql , :postgres , :oracle , :postgis
49- 'NULLS LAST'
50- when :mysql , :mysql2 , :trilogy , :sqlite , :sqlite3
51- 'IS NULL'
52- else
53- raise "unsupported database adapter: #{ @adapter } "
54- end
66+ NULL_STYLE_MAP [ @adapter ] || raise ( "unsupported database adapter: #{ @adapter } " )
5567 end
5668
5769 end
0 commit comments