Class: ActiveRecord::ConnectionAdapters::CrateAdapter::TableDefinition
- Inherits:
-
TableDefinition
- Object
- TableDefinition
- ActiveRecord::ConnectionAdapters::CrateAdapter::TableDefinition
- Defined in:
- lib/active_record/connection_adapters/crate_adapter.rb
Instance Method Summary collapse
- #array(name, options = {}) ⇒ Object
- #column(name, type = nil, options = {}) ⇒ Object
- #object(name, options = {}) ⇒ Object
-
#primary_key(name, type = :primary_key, options = {}) ⇒ Object
Crate doesn’t support auto incrementing, therefore we need to manually set a primary key.
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, = {}) array_type = .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})", .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, = {}) super column = self[name] column.array = [:array] column.object = [: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, = {}) schema_behaviour = .delete(:object_schema_behaviour) type = schema_behaviour ? "object(#{schema_behaviour})" : schema_behaviour schema = .delete(:object_schema) type = "#{type} as (#{object_schema_to_string(schema)})" if schema column name, type, .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, = {}) [:primary_key] = true column name, "STRING PRIMARY KEY", end |