Class: TableCopy::PG::Field

Inherits:
Object
  • Object
show all
Defined in:
lib/table_copy/pg/field.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attrs) ⇒ Field

Returns a new instance of Field.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/table_copy/pg/field.rb', line 6

def initialize(attrs)
  @name = attrs['column_name']
  data_type = attrs['data_type']

  if data_type =~ /character/
    @data_limit = attrs['character_maximum_length']
  end

  if data_type == 'ARRAY' && attrs['udt_name'] == '_varchar'
    @type_name = 'character varying'
    @data_limit = '256'
    @array_ddl = '[]'
  end

  @type_name ||= data_type
end

Instance Attribute Details

#data_limitObject (readonly)

Returns the value of attribute data_limit.



4
5
6
# File 'lib/table_copy/pg/field.rb', line 4

def data_limit
  @data_limit
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/table_copy/pg/field.rb', line 4

def name
  @name
end

#type_nameObject (readonly)

Returns the value of attribute type_name.



4
5
6
# File 'lib/table_copy/pg/field.rb', line 4

def type_name
  @type_name
end

Instance Method Details

#auto_index?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/table_copy/pg/field.rb', line 27

def auto_index?
  @type_name =~ /int|timestamp|bool/
end

#ddlObject



23
24
25
# File 'lib/table_copy/pg/field.rb', line 23

def ddl
  @ddl ||= "#{name} #{type_name}#{data_limit_ddl}#{array_ddl}"
end