Class: ActiveRecord::ConnectionAdapters::CrateAdapter::TableDefinition

Inherits:
TableDefinition
  • Object
show all
Defined in:
lib/active_record/connection_adapters/crate_adapter.rb

Instance Method Summary collapse

Instance Method Details

#array(name, options = {}) ⇒ Object



195
196
197
198
199
# File 'lib/active_record/connection_adapters/crate_adapter.rb', line 195

def array(name, options = {})
  array_type = options.delete(:array_type)
  raise "Array columns must specify an :array_type (e.g. array_type: :string)" unless array_type.present?
  column name, "array(#{array_type})", options.merge(array: true)
end

#column(name, type = nil, options = {}) ⇒ Object



178
179
180
181
182
183
184
# File 'lib/active_record/connection_adapters/crate_adapter.rb', line 178

def column(name, type = nil, options = {})
  super
  column = self[name]
  column.array = options[:array]
  column.object = options[:object]
  self
end

#object(name, options = {}) ⇒ Object



186
187
188
189
190
191
192
193
# File 'lib/active_record/connection_adapters/crate_adapter.rb', line 186

def object(name, options = {})
  schema_behaviour = options.delete(:object_schema_behaviour)
  type = schema_behaviour ? "object(#{schema_behaviour})" : schema_behaviour
  schema = options.delete(:object_schema)
  type = "#{type} as (#{object_schema_to_string(schema)})" if schema

  column name, type, options.merge(object: true)
end

#primary_key(name, type = :primary_key, options = {}) ⇒ Object

Crate doesn’t support auto incrementing, therefore we need to manually set a primary key. You need to assure that you always provide an unique id. This might be done via the SecureRandom.uuid method and a before_save callback, for instance.



173
174
175
176
# File 'lib/active_record/connection_adapters/crate_adapter.rb', line 173

def primary_key(name, type = :primary_key, options = {})
  options[:primary_key] = true
  column name, "STRING PRIMARY KEY", options
end