@@ -41,17 +41,29 @@ def sort_nulls_last?
41
41
column . nulls_last? || @nulls_last == true
42
42
end
43
43
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
+
44
63
def nulls_last_sql
45
64
return unless sort_nulls_last?
46
65
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 } " )
55
67
end
56
68
57
69
end
0 commit comments