Module: Cequel::Record::Properties::ClassMethods
- Defined in:
- lib/cequel/record/properties.rb
Overview
Methods for defining columns on a record
Instance Method Summary collapse
-
#column(name, type, options = {}) ⇒ void
Define a data column.
-
#key(name, type, options = {}) ⇒ void
Define a key column.
-
#list(name, type, options = {}) ⇒ void
Define a list column.
-
#map(name, key_type, value_type, options = {}) ⇒ void
Define a map column.
-
#set(name, type, options = {}) ⇒ void
Define a set column.
Instance Method Details
#column(name, type, options = {}) ⇒ void
Using type :enum will behave similar to an ActiveRecord enum: example: ‘column :status, :enum, values: { open: 1, closed: 2 }` will be handled as type Int calling model.status will return the symbol ie. :open or :closed expects setter to be called with symbol ie. model.status(:open) exposes helpers ie. model.open? exposes values-mapping on a class-level ModelClass.status
Secondary indexes are not nearly as flexible as primary keys: you cannot query for multiple values or for ranges of values. You also cannot combine a secondary index restriction with a primary key restriction in the same query, nor can you combine more than one secondary index restriction in the same query.
This method returns an undefined value.
Define a data column
140 141 142 143 144 |
# File 'lib/cequel/record/properties.rb', line 140 def column(name, type, = {}) def_accessors(name) def_enum(name, [:values]) if type == :enum set_attribute_default(name, [:default]) end |
#key(name, type, options = {}) ⇒ void
belongs_to implicitly defines key columns.
This method returns an undefined value.
Define a key column. By default, the first key column defined for a record will be a partition key, and the following keys will be clustering columns. This behavior can be changed using the ‘:partition` option
99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/cequel/record/properties.rb', line 99 def key(name, type, = {}) def_accessors(name) if .fetch(:auto, false) unless Type[type].is_a?(Cequel::Type::Uuid) fail ArgumentError, ":auto option only valid for UUID columns" end default = -> { Cequel.uuid } if [:auto] else default = [:default] end set_attribute_default(name, default) end |
#list(name, type, options = {}) ⇒ void
This method returns an undefined value.
Define a list column
159 160 161 162 163 |
# File 'lib/cequel/record/properties.rb', line 159 def list(name, type, = {}) def_collection_accessors(name, List) set_attribute_default(name, [:default]) set_empty_attribute(name) { [] } end |
#map(name, key_type, value_type, options = {}) ⇒ void
This method returns an undefined value.
Define a map column
197 198 199 200 201 |
# File 'lib/cequel/record/properties.rb', line 197 def map(name, key_type, value_type, = {}) def_collection_accessors(name, Map) set_attribute_default(name, [:default]) set_empty_attribute(name) { {} } end |
#set(name, type, options = {}) ⇒ void
This method returns an undefined value.
Define a set column
178 179 180 181 182 |
# File 'lib/cequel/record/properties.rb', line 178 def set(name, type, = {}) def_collection_accessors(name, Set) set_attribute_default(name, [:default]) set_empty_attribute(name) { ::Set[] } end |