Class: ActiveRecord::ConnectionAdapters::CockroachDB::Column

Inherits:
PostgreSQL::Column
  • Object
show all
Defined in:
lib/active_record/connection_adapters/cockroachdb/column.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, cast_type, default, sql_type_metadata = nil, null = true, default_function = nil, collation: nil, comment: nil, identity: nil, serial: nil, generated: nil, hidden: nil) ⇒ Column



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/active_record/connection_adapters/cockroachdb/column.rb', line 23

def initialize(name, cast_type, default,  = nil, null = true,
               default_function = nil, collation: nil, comment: nil, identity: nil,
               serial: nil, generated: nil, hidden: nil)

  super(name, cast_type, default, , null, default_function,
    collation: collation, comment: comment, serial: serial, generated: generated, identity: identity)

  @hidden = hidden

  return unless spatial?

  @geographic = .sql_type.match?(/geography\(/i)

  if @geographic
    # Geographic type information is embedded in the SQL type
    @srid = 4326
    @has_z = @has_m = false
    build_from_sql_type(.sql_type)
  elsif sql_type.match?(/geography|geometry|point|linestring|polygon/i)
    build_from_sql_type(.sql_type)
  elsif .sql_type.match?(/geography|geometry|point|linestring|polygon/i)
    # A geometry column with no geometry_columns entry.
    # @geometric_type = geo_type_from_sql_type(sql_type)
    build_from_sql_type(.sql_type)
  end

  if spatial? && @srid
    @limit = { srid: @srid, type: to_type_name(geometric_type) }
    @limit[:has_z] = true if @has_z
    @limit[:has_m] = true if @has_m
    @limit[:geographic] = true if @geographic
  end
end

Instance Attribute Details

#geographic ⇒ Object (readonly) Also known as: geographic?

Returns the value of attribute geographic.



57
58
59
# File 'lib/active_record/connection_adapters/cockroachdb/column.rb', line 57

def geographic
  @geographic
end

#geometric_type ⇒ Object (readonly)

Returns the value of attribute geometric_type.



57
58
59
# File 'lib/active_record/connection_adapters/cockroachdb/column.rb', line 57

def geometric_type
  @geometric_type
end

#has_m ⇒ Object (readonly) Also known as: has_m?

Returns the value of attribute has_m.



57
58
59
# File 'lib/active_record/connection_adapters/cockroachdb/column.rb', line 57

def has_m
  @has_m
end

#has_z ⇒ Object (readonly) Also known as: has_z?

Returns the value of attribute has_z.



57
58
59
# File 'lib/active_record/connection_adapters/cockroachdb/column.rb', line 57

def has_z
  @has_z
end

#hidden ⇒ Object (readonly) Also known as: hidden?

Returns the value of attribute hidden.



57
58
59
# File 'lib/active_record/connection_adapters/cockroachdb/column.rb', line 57

def hidden
  @hidden
end

#srid ⇒ Object (readonly)

Returns the value of attribute srid.



57
58
59
# File 'lib/active_record/connection_adapters/cockroachdb/column.rb', line 57

def srid
  @srid
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?

TODO: add tests (see #390)



106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/active_record/connection_adapters/cockroachdb/column.rb', line 106

def ==(other)
  other.is_a?(Column) &&
    super &&
    other.geographic == geographic &&
    other.geometric_type == geometric_type &&
    other.has_m == has_m &&
    other.has_z == has_z &&
    other.srid == srid &&
    other.hidden == hidden &&
    other.limit == limit

end

#encode_with(coder) ⇒ Object

TODO: add tests (see #390)



94
95
96
97
98
99
100
101
102
103
# File 'lib/active_record/connection_adapters/cockroachdb/column.rb', line 94

def encode_with(coder)
  coder["geographic"] = @geographic
  coder["geometric_type"] = @geometric_type
  coder["has_m"] = @has_m
  coder["has_z"] = @has_z
  coder["srid"] = @srid
  coder["hidden"] = @hidden
  coder["limit"] = @limit
  super
end

#hash ⇒ Object

TODO: add tests (see #390)



121
122
123
124
125
126
127
128
129
130
131
# File 'lib/active_record/connection_adapters/cockroachdb/column.rb', line 121

def hash
  Column.hash ^
    super.hash ^
    geographic.hash ^
    geometric_type.hash ^
    has_m.hash ^
    has_z.hash ^
    srid.hash ^
    hidden.hash ^
    limit.hash
end

#init_with(coder) ⇒ Object

TODO: add tests (see #390)



82
83
84
85
86
87
88
89
90
91
# File 'lib/active_record/connection_adapters/cockroachdb/column.rb', line 82

def init_with(coder)
  @geographic = coder["geographic"]
  @geometric_type = coder["geometric_type"]
  @has_m = coder["has_m"]
  @has_z = coder["has_z"]
  @srid = coder["srid"]
  @hidden = coder["hidden"]
  @limit = coder["limit"]
  super
end

#limit ⇒ Object



69
70
71
# File 'lib/active_record/connection_adapters/cockroachdb/column.rb', line 69

def limit
  spatial? ? @limit : super
end

#serial? ⇒ Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/active_record/connection_adapters/cockroachdb/column.rb', line 77

def serial?
  default_function == 'unique_rowid()'
end

#spatial? ⇒ Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/active_record/connection_adapters/cockroachdb/column.rb', line 73

def spatial?
  %i[geometry geography].include?(@sql_type_metadata.type)
end