Class: ThinkingSphinx::ActiveRecord::DatabaseAdapters::PostgreSQLAdapter

Inherits:
AbstractAdapter
  • Object
show all
Defined in:
lib/thinking_sphinx/active_record/database_adapters/postgresql_adapter.rb

Instance Method Summary collapse

Methods inherited from AbstractAdapter

#initialize, #quote, #quoted_table_name, #utf8_query_pre

Constructor Details

This class inherits a constructor from ThinkingSphinx::ActiveRecord::DatabaseAdapters::AbstractAdapter

Instance Method Details

#boolean_value(value) ⇒ Object



4
5
6
# File 'lib/thinking_sphinx/active_record/database_adapters/postgresql_adapter.rb', line 4

def boolean_value(value)
  value ? 'TRUE' : 'FALSE'
end

#cast_to_string(clause) ⇒ Object



8
9
10
# File 'lib/thinking_sphinx/active_record/database_adapters/postgresql_adapter.rb', line 8

def cast_to_string(clause)
  "#{clause}::varchar"
end

#cast_to_timestamp(clause) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/thinking_sphinx/active_record/database_adapters/postgresql_adapter.rb', line 12

def cast_to_timestamp(clause)
  if ThinkingSphinx::Configuration.instance.settings['64bit_timestamps']
    "extract(epoch from #{clause})::bigint"
  else
    "extract(epoch from #{clause})::int"
  end
end

#concatenate(clause, separator = ' ') ⇒ Object



20
21
22
23
24
# File 'lib/thinking_sphinx/active_record/database_adapters/postgresql_adapter.rb', line 20

def concatenate(clause, separator = ' ')
  clause.split(', ').collect { |part|
    convert_nulls(part, "''")
  }.join(" || '#{separator}' || ")
end

#convert_nulls(clause, default = '') ⇒ Object



26
27
28
# File 'lib/thinking_sphinx/active_record/database_adapters/postgresql_adapter.rb', line 26

def convert_nulls(clause, default = '')
  "COALESCE(#{clause}, #{default})"
end

#group_concatenate(clause, separator = ' ') ⇒ Object



30
31
32
# File 'lib/thinking_sphinx/active_record/database_adapters/postgresql_adapter.rb', line 30

def group_concatenate(clause, separator = ' ')
  "array_to_string(array_agg(#{clause}), '#{separator}')"
end

#time_zone_query_preObject



34
35
36
# File 'lib/thinking_sphinx/active_record/database_adapters/postgresql_adapter.rb', line 34

def time_zone_query_pre
  ['SET TIME ZONE UTC']
end