Module: SimpleNestedSet::SqlAbstraction

Included in:
NestedSet, Rebuild::FromParents
Defined in:
lib/simple_nested_set/sql_abstraction.rb

Overview

database-specific statements, ready to be inserted into arel.project()

Instance Method Summary collapse

Instance Method Details

#group_concat(database, field, separator = '/') ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/simple_nested_set/sql_abstraction.rb', line 5

def group_concat(database, field, separator = '/')
  case database.to_sym
  when :sqlite, :sqlite3
    "GROUP_CONCAT(#{field}, '#{separator}')"
  when :mysql, :mysql2
    "GROUP_CONCAT(`#{field}` SEPARATOR '#{separator}')"
  when :postgresql
    "array_to_string(array_agg(\"#{field}\"), '#{separator}')"
  else
    raise ArgumentError, "#{database} is not supported by SimpleNestedSet::SqlAbstraction#group_concat"
  end
end

#order_by(database, order) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/simple_nested_set/sql_abstraction.rb', line 18

def order_by(database, order)
  case database.to_sym
  when :sqlite, :sqlite3
    order.to_s
  when :mysql, :mysql2
    "`#{order }`"
  when :postgresql
    "\"#{order}\" NULLS FIRST"
  end
end