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
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
132 133 134 135 |
# File 'lib/cequel/record/properties.rb', line 132 def column(name, type, = {}) def_accessors(name) 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
150 151 152 153 154 |
# File 'lib/cequel/record/properties.rb', line 150 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
188 189 190 191 192 |
# File 'lib/cequel/record/properties.rb', line 188 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
169 170 171 172 173 |
# File 'lib/cequel/record/properties.rb', line 169 def set(name, type, = {}) def_collection_accessors(name, Set) set_attribute_default(name, [:default]) set_empty_attribute(name) { ::Set[] } end |