Class: Insertica::Column

Inherits:
Object
  • Object
show all
Defined in:
lib/insertica/column.rb

Constant Summary collapse

ESCAPE_CHARACTERS =
["\n", "\t", "\""]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, values = []) ⇒ Column

Returns a new instance of Column.



11
12
13
14
15
# File 'lib/insertica/column.rb', line 11

def initialize(name, values = [])
  @name   = name
  @type   = nil
  @values = values
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



7
8
9
# File 'lib/insertica/column.rb', line 7

def name
  @name
end

#typeObject

Returns the value of attribute type.



9
10
11
# File 'lib/insertica/column.rb', line 9

def type
  @type
end

#valuesObject

Returns the value of attribute values.



8
9
10
# File 'lib/insertica/column.rb', line 8

def values
  @values
end

Instance Method Details

#definitionObject



24
25
26
# File 'lib/insertica/column.rb', line 24

def definition
  "#{@name} #{@type}"
end

#filler_definitionObject



28
29
30
# File 'lib/insertica/column.rb', line 28

def filler_definition
  "#{@name}_filler FILLER VARCHAR"
end

#finalizeObject



17
18
19
20
21
22
# File 'lib/insertica/column.rb', line 17

def finalize
  @type = ColumnType.new(@values)
  escape_strings if @type.needs_escaping?

  self
end

#fix_nulls_definitionObject



32
33
34
# File 'lib/insertica/column.rb', line 32

def fix_nulls_definition
  "#{@name} AS CASE WHEN #{@name}_filler = '' THEN NULL ELSE #{@name}_filler::#{@type} END"
end