Class: ActiveRecordSpannerAdapter::Table::Column

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table_name, name, type, schema_name: "", limit: nil, ordinal_position: nil, nullable: true, allow_commit_timestamp: nil, default: nil, default_function: nil, generated: nil, primary_key: false) ⇒ Column

Returns a new instance of Column.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/activerecord_spanner_adapter/table/column.rb', line 14

def initialize \
    table_name,
    name,
    type,
    schema_name: "",
    limit: nil,
    ordinal_position: nil,
    nullable: true,
    allow_commit_timestamp: nil,
    default: nil,
    default_function: nil,
    generated: nil,
    primary_key: false
  @schema_name = schema_name.to_s
  @table_name = table_name.to_s
  @name = name.to_s
  @type = type
  @limit = limit
  @nullable = nullable != false
  @ordinal_position = ordinal_position
  @allow_commit_timestamp = allow_commit_timestamp
  @default = default
  @default_function = default_function
  @generated = generated == true
  @primary_key = primary_key
end

Instance Attribute Details

#allow_commit_timestampObject

Returns the value of attribute allow_commit_timestamp.



10
11
12
# File 'lib/activerecord_spanner_adapter/table/column.rb', line 10

def allow_commit_timestamp
  @allow_commit_timestamp
end

#defaultObject

Returns the value of attribute default.



10
11
12
# File 'lib/activerecord_spanner_adapter/table/column.rb', line 10

def default
  @default
end

#default_functionObject

Returns the value of attribute default_function.



10
11
12
# File 'lib/activerecord_spanner_adapter/table/column.rb', line 10

def default_function
  @default_function
end

#generatedObject

Returns the value of attribute generated.



10
11
12
# File 'lib/activerecord_spanner_adapter/table/column.rb', line 10

def generated
  @generated
end

#limitObject

Returns the value of attribute limit.



10
11
12
# File 'lib/activerecord_spanner_adapter/table/column.rb', line 10

def limit
  @limit
end

#nameObject

Returns the value of attribute name.



10
11
12
# File 'lib/activerecord_spanner_adapter/table/column.rb', line 10

def name
  @name
end

#nullableObject

Returns the value of attribute nullable.



10
11
12
# File 'lib/activerecord_spanner_adapter/table/column.rb', line 10

def nullable
  @nullable
end

#ordinal_positionObject

Returns the value of attribute ordinal_position.



10
11
12
# File 'lib/activerecord_spanner_adapter/table/column.rb', line 10

def ordinal_position
  @ordinal_position
end

#primary_keyObject

Returns the value of attribute primary_key.



10
11
12
# File 'lib/activerecord_spanner_adapter/table/column.rb', line 10

def primary_key
  @primary_key
end

#schema_nameObject

Returns the value of attribute schema_name.



10
11
12
# File 'lib/activerecord_spanner_adapter/table/column.rb', line 10

def schema_name
  @schema_name
end

#table_nameObject

Returns the value of attribute table_name.



10
11
12
# File 'lib/activerecord_spanner_adapter/table/column.rb', line 10

def table_name
  @table_name
end

#typeObject

Returns the value of attribute type.



10
11
12
# File 'lib/activerecord_spanner_adapter/table/column.rb', line 10

def type
  @type
end

Instance Method Details

#optionsObject



46
47
48
49
50
51
52
# File 'lib/activerecord_spanner_adapter/table/column.rb', line 46

def options
  {
    limit: limit,
    null: nullable,
    allow_commit_timestamp: allow_commit_timestamp
  }.delete_if { |_, v| v.nil? }
end

#spanner_typeObject



41
42
43
44
# File 'lib/activerecord_spanner_adapter/table/column.rb', line 41

def spanner_type
  return "#{type}(#{limit || 'MAX'})" if limit_allowed?
  type
end