Module: ArJdbc::PostgreSQL::Column

Defined in:
lib/arjdbc/postgresql/adapter.rb

Instance Method Summary collapse

Instance Method Details

#cast_to_boolean(value) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/arjdbc/postgresql/adapter.rb', line 49

def cast_to_boolean(value)
  return nil if value.nil?
  if value == true || value == false
    value
  else
    %w(true t 1).include?(value.to_s.downcase)
  end
end

#default_value(value) ⇒ Object

Post process default value from JDBC into a Rails-friendly format (columns-internal)



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/arjdbc/postgresql/adapter.rb', line 59

def default_value(value)
  # Boolean types
  return "t" if value =~ /true/i
  return "f" if value =~ /false/i

  # Char/String/Bytea type values
  return $1 if value =~ /^'(.*)'::(bpchar|text|character varying|bytea)$/

  # Numeric values
  return value if value =~ /^-?[0-9]+(\.[0-9]*)?/

  # Fixed dates / timestamp
  return $1 if value =~ /^'(.+)'::(date|timestamp)/

  # Anything else is blank, some user type, or some function
  # and we can't know the value of that, so return nil.
  return nil
end

#extract_limit(sql_type) ⇒ Object



29
30
31
32
33
34
35
36
# File 'lib/arjdbc/postgresql/adapter.rb', line 29

def extract_limit(sql_type)
  case sql_type
  when /^bigint/i;    8
  when /^smallint/i;  2
  when /^(bool|text|date|time)/i; nil # ACTIVERECORD_JDBC-135,139
  else super
  end
end

#simplified_type(field_type) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/arjdbc/postgresql/adapter.rb', line 38

def simplified_type(field_type)
  return :integer if field_type =~ /^serial/i
  return :string if field_type =~ /\[\]$/i || field_type =~ /^interval/i
  return :string if field_type =~ /^(?:point|lseg|box|"?path"?|polygon|circle)/i
  return :datetime if field_type =~ /^timestamp/i
  return :float if field_type =~ /^(?:real|double precision)$/i
  return :binary if field_type =~ /^bytea/i
  return :boolean if field_type =~ /^bool/i
  super
end

#type_cast(value) ⇒ Object



22
23
24
25
26
27
# File 'lib/arjdbc/postgresql/adapter.rb', line 22

def type_cast(value)
  case type
  when :boolean then cast_to_boolean(value)
  else super
  end
end