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
190 191 192 193 194 |
# File 'lib/active_record/connection_adapters/crate_adapter.rb', line 190 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
173 174 175 176 177 178 179 |
# File 'lib/active_record/connection_adapters/crate_adapter.rb', line 173 def column(name, type = nil, = {}) super column = self[name] column.array = [:array] column.object = [:object] self end |
#object(name, options = {}) ⇒ Object
181 182 183 184 185 186 187 188 |
# File 'lib/active_record/connection_adapters/crate_adapter.rb', line 181 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.
168 169 170 171 |
# File 'lib/active_record/connection_adapters/crate_adapter.rb', line 168 def primary_key(name, type = :primary_key, = {}) [:primary_key] = true column name, "STRING PRIMARY KEY", end |