code
stringlengths 26
124k
| docstring
stringlengths 23
125k
| func_name
stringlengths 1
98
| language
stringclasses 1
value | repo
stringlengths 5
53
| path
stringlengths 7
151
| url
stringlengths 50
211
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
def loaded?(column = nil)
!!@loaded && (column.nil? || @cequel_attributes.key?(column.to_sym))
end
|
@overload loaded?
@return [Boolean] true if this record's attributes have been loaded
from the database
@overload loaded?(column)
@param [Symbol] column name of column to check if loaded
@return [Boolean] true if the named column is loaded in memory
@return [Boolean]
@since 1.0.0
|
loaded?
|
ruby
|
cequel/cequel
|
lib/cequel/record/persistence.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/persistence.rb
|
MIT
|
def save(options = {})
options.assert_valid_keys(:consistency, :ttl, :timestamp)
if new_record? then create(options)
else update(options)
end
@new_record = false
true
end
|
Persist the record to the database. If this is a new record, it will
be saved using an INSERT statement. If it is an existing record, it
will be persisted using a series of `UPDATE` and `DELETE` statements
which will persist all changes to the database, including atomic
collection modifications.
@param options [Options] options for save
@option options [Boolean] :validate (true) whether to run validations
before saving
@option options [Symbol] :consistency what consistency with
which to persist the changes
@option options [Integer] :ttl time-to-live of the updated rows in
seconds
@option options [Time] :timestamp the writetime to use for the column
updates
@return [Boolean] true if record saved successfully, false if invalid
@see Validations#save!
|
save
|
ruby
|
cequel/cequel
|
lib/cequel/record/persistence.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/persistence.rb
|
MIT
|
def update_attributes(attributes)
self.attributes = attributes
save
end
|
Set attributes and save the record
@param attributes [Hash] hash of attributes to update
@return [Boolean] true if saved successfully
@see #save
@see Properties#attributes=
@see Validations#update_attributes!
|
update_attributes
|
ruby
|
cequel/cequel
|
lib/cequel/record/persistence.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/persistence.rb
|
MIT
|
def destroy(options = {})
options.assert_valid_keys(:consistency, :timestamp)
assert_keys_present!
metal_scope.delete(options)
transient!
self
end
|
Remove this record from the database
@param options [Options] options for deletion
@option options [Symbol] :consistency what consistency with
which to persist the deletion
@option options [Time] :timestamp the writetime to use for the deletion
@return [Record] self
|
destroy
|
ruby
|
cequel/cequel
|
lib/cequel/record/persistence.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/persistence.rb
|
MIT
|
def column(name, type, options = {})
def_accessors(name)
def_enum(name, options[:values]) if type == :enum
set_attribute_default(name, options[:default])
end
|
rubocop:enable LineLength
Define a data column
@param name [Symbol] the name of the column
@param type [Symbol] the type of the column
@param options [Options] options for the column
@option options [Object,Proc] :default a default value for the
column, or a proc that returns a default value for the column
@option options [Boolean,Symbol] :index create a secondary index on
this column
@return [void]
@note 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
@note 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.
|
column
|
ruby
|
cequel/cequel
|
lib/cequel/record/properties.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/properties.rb
|
MIT
|
def list(name, type, options = {})
def_collection_accessors(name, List)
set_attribute_default(name, options[:default])
set_empty_attribute(name) { [] }
end
|
Define a list column
@param name [Symbol] the name of the list
@param type [Symbol] the type of the elements in the list
@param options [Options] options for the list
@option options [Object,Proc] :default ([]) a default value for the
column, or a proc that returns a default value for the column
@return [void]
@see Record::List
@since 1.0.0
|
list
|
ruby
|
cequel/cequel
|
lib/cequel/record/properties.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/properties.rb
|
MIT
|
def set(name, type, options = {})
def_collection_accessors(name, Set)
set_attribute_default(name, options[:default])
set_empty_attribute(name) { ::Set[] }
end
|
Define a set column
@param name [Symbol] the name of the set
@param type [Symbol] the type of the elements in the set
@param options [Options] options for the set
@option options [Object,Proc] :default (Set[]) a default value for
the column, or a proc that returns a default value for the column
@return [void]
@see Record::Set
@since 1.0.0
|
set
|
ruby
|
cequel/cequel
|
lib/cequel/record/properties.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/properties.rb
|
MIT
|
def map(name, key_type, value_type, options = {})
def_collection_accessors(name, Map)
set_attribute_default(name, options[:default])
set_empty_attribute(name) { {} }
end
|
Define a map column
@param name [Symbol] the name of the map
@param key_type [Symbol] the type of the keys in the set
@param options [Options] options for the set
@option options [Object,Proc] :default ({}) a default value for the
column, or a proc that returns a default value for the column
@return [void]
@see Record::Map
@since 1.0.0
|
map
|
ruby
|
cequel/cequel
|
lib/cequel/record/properties.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/properties.rb
|
MIT
|
def attributes
attribute_names
.each_with_object(HashWithIndifferentAccess.new) do |name, attributes|
attributes[name] = read_attribute(name)
end
end
|
@return [Hash<String,Object>] map of column names to values currently
set on this record
|
attributes
|
ruby
|
cequel/cequel
|
lib/cequel/record/properties.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/properties.rb
|
MIT
|
def inspect
inspected_attributes = attributes.each_pair.map do |attr, value|
inspected_value = Cequel.uuid?(value) ?
value.to_s :
value.inspect
"#{attr}: #{inspected_value}"
end
"#<#{self.class} #{inspected_attributes.join(", ")}>"
end
|
@return [String] string representation of the record
|
inspect
|
ruby
|
cequel/cequel
|
lib/cequel/record/properties.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/properties.rb
|
MIT
|
def initialize(target_class, attributes = {})
attributes = self.class.default_attributes.merge!(attributes)
@target_class, @cequel_attributes = target_class, attributes
super(target_class)
end
|
@param target_class [Class] the Record class that this collection
yields instances of
@param attributes [Hash] initial scoping attributes
@api private
|
initialize
|
ruby
|
cequel/cequel
|
lib/cequel/record/record_set.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/record_set.rb
|
MIT
|
def where(*args)
if args.length == 1
column_filters = args.first.symbolize_keys
elsif args.length == 2
warn "where(column_name, value) is deprecated. Use " \
"where(column_name => value) instead"
column_filters = {args.first.to_sym => args.second}
else
fail ArgumentError,
"wrong number of arguments (#{args.length} for 1..2)"
end
filter_columns(column_filters)
end
|
Filter the record set to records containing a given value in an indexed
column
@overload where(column_name, value)
@param column_name [Symbol] column for filter
@param value value to match in given column
@return [RecordSet] record set with filter applied
@deprecated
@overload where(column_values)
@param column_values [Hash] map of key column names to values
@return [RecordSet] record set with filter applied
@raise [IllegalQuery] if applying filter would generate an impossible
query
@raise [ArgumentError] if the specified column is not a column that
can be filtered on
@note Filtering on a primary key requires also filtering on all prior
primary keys
@note Only one secondary index filter can be used in a given query
@note Secondary index filters cannot be mixed with primary key filters
|
where
|
ruby
|
cequel/cequel
|
lib/cequel/record/record_set.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/record_set.rb
|
MIT
|
def at(*scoped_key_values)
warn "`at` is deprecated. Use `[]` instead"
traverse(*scoped_key_values)
end
|
@deprecated Use {#[]} instead
Scope to values for one or more primary key columns
@param scoped_key_values values for primary key columns
@return (see #[])
|
at
|
ruby
|
cequel/cequel
|
lib/cequel/record/record_set.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/record_set.rb
|
MIT
|
def values_at(*primary_key_values)
unless next_unscoped_key_column_valid_for_in_query?
fail IllegalQuery,
"Only the last partition key column and the last clustering " \
"column can match multiple values"
end
primary_key_values = primary_key_values.map(&method(:cast_range_key))
scope_and_resolve do |attributes|
attributes[:scoped_key_values] << primary_key_values
end
end
|
Restrict the records in this record set to those containing any of a
set of values
@param primary_key_values values to match in the next unscoped primary
key
@return [RecordSet] record set with primary key scope applied if not
all primary key columns are specified
@return [LazyRecordCollection] collection of unloaded records if all
primary key columns are specified
@raise IllegalQuery if the scoped key column is neither the last
partition key column nor the last clustering column
@see #[]
|
values_at
|
ruby
|
cequel/cequel
|
lib/cequel/record/record_set.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/record_set.rb
|
MIT
|
def find(*keys)
return super if block_given?
keys = [keys] if almost_fully_specified? && keys.many?
records = traverse(*keys).assert_fully_specified!.load!
force_array = keys.any? { |value| value.is_a?(Array) }
force_array ? Array.wrap(records) : records
end
|
Return a loaded Record or collection of loaded Records with the
specified primary key values
Multiple arguments are mapped onto unscoped key columns. To specify
multiple values for a given key column, use an array.
@param scoped_key_values one or more values for the final primary key
column
@return [Record] if a single key is specified, return the loaded
record at that key
@return [LazyRecordCollection] if multiple keys are specified, return a
collection of loaded records at those keys
@raise [RecordNotFound] if not all the keys correspond to records in
the table
@example One record with one-column primary key
# find the blog with subdomain 'cassandra'
Blog.find('cassandra')
@example Multiple records with one-column primary key
# find the blogs with subdomain 'cassandra' and 'postgres'
Blog.find(['cassandra', 'postgres'])
@example One record with two-column primary key
# find the post instance with blog subdomain 'cassandra' and
# permalink 'my-post'
Post.find('cassandra', 'my-post')
@example Multiple records with two-column primary key
# find the post instances with blog subdomain cassandra and
# permalinks 'my-post' and 'my-new-post'
Post.find('cassandra', ['my-post', 'my-new-post']
|
find
|
ruby
|
cequel/cequel
|
lib/cequel/record/record_set.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/record_set.rb
|
MIT
|
def after(start_key)
scoped(lower_bound: bound(true, false, start_key))
end
|
Restrict records to ones whose value in the first unscoped primary key
column are strictly greater than the given start_key.
@param start_key the exclusive lower bound for the key column
@return [RecordSet] record set with lower bound applied
@see #from
|
after
|
ruby
|
cequel/cequel
|
lib/cequel/record/record_set.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/record_set.rb
|
MIT
|
def before(end_key)
scoped(upper_bound: bound(false, false, end_key))
end
|
Restrict records to ones whose value in the first unscoped primary key
column are strictly less than the given end_key.
@param end_key the exclusive upper bound for the key column
@return [RecordSet] record set with upper bound applied
@see #upto
|
before
|
ruby
|
cequel/cequel
|
lib/cequel/record/record_set.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/record_set.rb
|
MIT
|
def in(range)
scoped(
lower_bound: bound(true, true, range.first),
upper_bound: bound(false, !range.exclude_end?, range.last)
)
end
|
Restrict records to those whose value in the first unscoped primary key
column are in the given range. Will accept both inclusive ranges
(`1..5`) and end-exclusive ranges (`1...5`). If you need a range with
an exclusive start value, use {#after}, which can be combined with
{#before} or {#from} to create a range.
@param range [Range] range of values for the key column
@return [RecordSet] record set with range restriction applied
@see #after
@see #before
@see #from
@see #upto
|
in
|
ruby
|
cequel/cequel
|
lib/cequel/record/record_set.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/record_set.rb
|
MIT
|
def from(start_key)
unless partition_specified?
fail IllegalQuery,
"Can't construct exclusive range on partition key " \
"#{range_key_name}"
end
scoped(lower_bound: bound(true, true, start_key))
end
|
Restrict records to those whose value in the first unscoped primary key
column are greater than or equal to the given start key.
@param start_key the inclusive lower bound for values in the key column
@return [RecordSet] record set with the lower bound applied
@see #after
|
from
|
ruby
|
cequel/cequel
|
lib/cequel/record/record_set.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/record_set.rb
|
MIT
|
def upto(end_key)
unless partition_specified?
fail IllegalQuery,
"Can't construct exclusive range on partition key " \
"#{range_key_name}"
end
scoped(upper_bound: bound(false, true, end_key))
end
|
Restrict records to those whose value in the first unscoped primary key
column are less than or equal to the given start key.
@param end_key the inclusive upper bound for values in the key column
@return [RecordSet] record set with the upper bound applied
@see #before
|
upto
|
ruby
|
cequel/cequel
|
lib/cequel/record/record_set.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/record_set.rb
|
MIT
|
def reverse
unless partition_specified?
fail IllegalQuery,
"Can't reverse without scoping to partition key " \
"#{range_key_name}"
end
scoped(reversed: !reversed?)
end
|
Reverse the order in which records will be returned from the record set
@return [RecordSet] record set with order reversed
@note This method can only be called on record sets whose partition key
columns are fully specified. See {#[]} for a discussion of partition
key scoping.
|
reverse
|
ruby
|
cequel/cequel
|
lib/cequel/record/record_set.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/record_set.rb
|
MIT
|
def consistency(consistency)
scoped(query_consistency: consistency)
end
|
Set the consistency at which to read records into the record set.
@param consistency [Symbol] consistency for reads
@return [RecordSet] record set tuned to given consistency
|
consistency
|
ruby
|
cequel/cequel
|
lib/cequel/record/record_set.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/record_set.rb
|
MIT
|
def allow_filtering!
scoped(allow_filtering: true)
end
|
Add `ALLOW FILTERING` to select-queries for filtering of none-indexed fields.
`Post.allow_filtering!.where(title: 'Cequel 0')`
Available as of Cassandra 3.6
@return [RecordSet] record set tuned to given consistency
@see https://docs.datastax.com/en/cql/3.3/cql/cql_reference/cqlSelect.html#cqlSelect__filtering-on-clustering-column
@note Filtering can incurr a significant performance overhead or even timeout on a large data-set.
|
allow_filtering!
|
ruby
|
cequel/cequel
|
lib/cequel/record/record_set.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/record_set.rb
|
MIT
|
def page_size(page_size)
scoped(query_page_size: page_size)
end
|
Set the page_size at which to read records into the record set.
@param page_size [Integer] page_size for reads
@return [RecordSet] record set tuned to given page_size
|
page_size
|
ruby
|
cequel/cequel
|
lib/cequel/record/record_set.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/record_set.rb
|
MIT
|
def paging_state(paging_state)
scoped(query_paging_state: paging_state)
end
|
Set the paging_state at which to read records into the record set.
@param paging_state [String] paging_state for reads
@return [RecordSet] record set tuned to given paging_state
|
paging_state
|
ruby
|
cequel/cequel
|
lib/cequel/record/record_set.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/record_set.rb
|
MIT
|
def first(count = nil)
count ? limit(count).entries : limit(1).each.first
end
|
@overload first
@return [Record] the first record in this record set
@overload first(count)
@param count [Integer] how many records to return
@return [Array] the first `count` records of the record set
@return [Record,Array]
|
first
|
ruby
|
cequel/cequel
|
lib/cequel/record/record_set.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/record_set.rb
|
MIT
|
def first_or_initialize
first || new
end
|
@return [Record] the first record or a new instance
|
first_or_initialize
|
ruby
|
cequel/cequel
|
lib/cequel/record/record_set.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/record_set.rb
|
MIT
|
def first!
first or fail(RecordNotFound,
"Couldn't find record with keys: #{
scoped_key_attributes.map { |k, v|
"#{k}: #{v}" }.join(', ')}")
end
|
@return [Record] the first record
@raise [RecordNotFound] if the record set is empty
|
first!
|
ruby
|
cequel/cequel
|
lib/cequel/record/record_set.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/record_set.rb
|
MIT
|
def last(count = nil)
reverse.first(count).tap do |results|
results.reverse! if count
end
end
|
@overload last
@return [Record] the last record in this record set
@overload last(count)
@param count [Integer] how many records to return
@return [Array] the last `count` records in the record set in
ascending order
@return [Record,Array]
|
last
|
ruby
|
cequel/cequel
|
lib/cequel/record/record_set.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/record_set.rb
|
MIT
|
def count
raise Cequel::Record::DangerousQueryError.new
end
|
@raise [DangerousQueryError] to prevent loading the entire record set
to be counted
|
count
|
ruby
|
cequel/cequel
|
lib/cequel/record/record_set.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/record_set.rb
|
MIT
|
def find_each(options = {})
return enum_for(:find_each, options) unless block_given?
find_each_row(options) { |row| yield target_class.hydrate(row) }
end
|
Enumerate over the records in this record set, with control over how
the database is queried
@param (see #find_rows_in_batches)
@yieldparam (see #each)
@option (see #find_rows_in_batches)
@return (see #each)
@see #find_in_batches
|
find_each
|
ruby
|
cequel/cequel
|
lib/cequel/record/record_set.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/record_set.rb
|
MIT
|
def find_in_batches(options = {})
return enum_for(:find_in_batches, options) unless block_given?
find_rows_in_batches(options) do |rows|
yield rows.map { |row| target_class.hydrate(row) }
end
end
|
Enumerate over the records in this record set in batches. Note that the
given batch_size controls the maximum number of records that can be
returned per query, but no batch is guaranteed to be exactly the given
`batch_size`
@param (see #find_rows_in_batches)
@option (see #find_rows_in_batches)
@yieldparam batch [Array<Record>] batch of records
@return (see #each)
|
find_in_batches
|
ruby
|
cequel/cequel
|
lib/cequel/record/record_set.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/record_set.rb
|
MIT
|
def find_each_row(options = {}, &block)
return enum_for(:find_each_row, options) unless block
find_rows_in_batches(options) { |rows| rows.each(&block) }
end
|
Enumerate over the row data for each record in this record set, without
hydrating an actual {Record} instance. Useful for operations where
speed is at a premium.
@param (see #find_rows_in_batches)
@option (see #find_rows_in_batches)
@yieldparam row [Hash<Symbol,Object>] a hash of column names to values
for each row
@return (see #each)
@see #find_rows_in_batches
|
find_each_row
|
ruby
|
cequel/cequel
|
lib/cequel/record/record_set.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/record_set.rb
|
MIT
|
def find_rows_in_batches(options = {}, &block)
return find_rows_in_single_batch(options, &block) if row_limit
options.assert_valid_keys(:batch_size)
batch_size = options.fetch(:batch_size, 1000)
batch_record_set = base_record_set = limit(batch_size)
more_results = true
while more_results
rows = batch_record_set.find_rows_in_single_batch
yield rows if rows.any?
more_results = rows.length == batch_size
last_row = rows.last
if more_results
find_nested_batches_from(last_row, options, &block)
batch_record_set = base_record_set.next_batch_from(last_row)
end
end
end
|
Enumerate over batches of row data for the records in this record set.
@param options [Options] options for querying the database
@option options [Integer] :batch_size (1000) the maximum number of rows
to return per batch query
@yieldparam batch [Array<Hash<Symbol,Object>>] a batch of rows
@return (see #each)
@see #find_each_row
@see #find_in_batches
|
find_rows_in_batches
|
ruby
|
cequel/cequel
|
lib/cequel/record/record_set.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/record_set.rb
|
MIT
|
def data_set
@data_set ||= construct_data_set
end
|
@return [Cequel::Metal::DataSet] the data set underlying this record
set
|
data_set
|
ruby
|
cequel/cequel
|
lib/cequel/record/record_set.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/record_set.rb
|
MIT
|
def scoped_key_attributes
Hash[scoped_key_columns.map { |col| col.name }.zip(scoped_key_values)]
end
|
@return [Hash] map of key column names to the values that have been
specified in this record set
|
scoped_key_attributes
|
ruby
|
cequel/cequel
|
lib/cequel/record/record_set.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/record_set.rb
|
MIT
|
def without_bounds_on(column)
without_lower_bound_on(column)
.without_upper_bound_on(column)
end
|
@return [RecordSet] self but without any bounds conditions on
the specified column.
@private
|
without_bounds_on
|
ruby
|
cequel/cequel
|
lib/cequel/record/record_set.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/record_set.rb
|
MIT
|
def synchronize_schema
fail MissingTableNameError unless table_name
patch =
begin
existing_table_descriptor = Cequel::Schema::TableReader.read(connection,
table_name)
return if existing_table_descriptor.materialized_view?
Cequel::Schema::TableDiffer.new(existing_table_descriptor,
table_schema)
.call
rescue NoSuchTableError
Cequel::Schema::TableWriter.new(table_schema)
end
patch.statements.each { |stmt| connection.execute(stmt) }
end
|
Read the current schema assigned to this record's table from
Cassandra, and make any necessary modifications (including creating
the table for the first time) so that it matches the schema defined
in the record definition
@raise (see Schema::TableSynchronizer.apply)
@return [void]
|
synchronize_schema
|
ruby
|
cequel/cequel
|
lib/cequel/record/schema.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/schema.rb
|
MIT
|
def create!(attributes = {}, &block)
new(attributes, &block).save!
end
|
Attempt to create a new record, or raise an exception otherwise
@param (see Persistence::ClassMethods#create)
@yieldparam (see Persistence::ClassMethods#create)
@return (see Persistence::ClassMethods#create)
@raise (see Validations#save!)
|
create!
|
ruby
|
cequel/cequel
|
lib/cequel/record/validations.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/validations.rb
|
MIT
|
def save!(attributes = {})
tap do
unless save(attributes)
fail RecordInvalid, errors.full_messages.join("; ")
end
end
end
|
Attempt to save the record, or raise an exception if there is a
validation error
@param (see Persistence#save)
@return [Record] self
@raise [RecordInvalid] if there are validation errors
|
save!
|
ruby
|
cequel/cequel
|
lib/cequel/record/validations.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/validations.rb
|
MIT
|
def update_attributes!(attributes)
self.attributes = attributes
save!
end
|
Set the given attributes and attempt to save, raising an exception if
there is a validation error
@param (see Persistence#update_attributes)
@return (see #save!)
@raise (see #save!)
|
update_attributes!
|
ruby
|
cequel/cequel
|
lib/cequel/record/validations.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/record/validations.rb
|
MIT
|
def initialize(name, type)
@name, @type = name, type
end
|
@param name [Symbol] the name of the column
@param type [Type] the type of the column
|
initialize
|
ruby
|
cequel/cequel
|
lib/cequel/schema/column.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/column.rb
|
MIT
|
def type?(type_in)
type == Type[type_in]
end
|
@param type_in [Symbol,Type] type to check against
@return [Boolean] true if this column has the type given by `type_in`
|
type?
|
ruby
|
cequel/cequel
|
lib/cequel/schema/column.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/column.rb
|
MIT
|
def to_cql
%Q|"#{@name}" #{@type}|
end
|
@return [String] a CQL fragment representing this column in a table
definition
@api private
|
to_cql
|
ruby
|
cequel/cequel
|
lib/cequel/schema/column.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/column.rb
|
MIT
|
def inspect
%Q(#<#{self.class.name}: #{to_cql}>)
end
|
@return [String] human-readable representation of this column
|
inspect
|
ruby
|
cequel/cequel
|
lib/cequel/schema/column.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/column.rb
|
MIT
|
def initialize(name, type, clustering_order = nil)
super(name, type)
@clustering_order = (clustering_order || :asc).to_sym
end
|
@param (see Column#initialize)
@param clustering_order [:asc,:desc] ascending or descending order for
this column
|
initialize
|
ruby
|
cequel/cequel
|
lib/cequel/schema/column.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/column.rb
|
MIT
|
def initialize(name, type, index_name = nil)
super(name, type)
@index_name = index_name
end
|
@param (see Column#initialize)
@param index_name [Symbol] name this column's secondary index
|
initialize
|
ruby
|
cequel/cequel
|
lib/cequel/schema/column.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/column.rb
|
MIT
|
def cast(value)
value.map { |element| @type.cast(element) }
end
|
@return [Array] array with elements cast to correct type for column
|
cast
|
ruby
|
cequel/cequel
|
lib/cequel/schema/column.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/column.rb
|
MIT
|
def cast(value)
value.to_set { |element| @type.cast(element) }
end
|
@param (see Column#cast)
@return [::Set] set with elements cast to correct type for column
|
cast
|
ruby
|
cequel/cequel
|
lib/cequel/schema/column.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/column.rb
|
MIT
|
def initialize(name, key_type, value_type)
super(name, value_type)
@key_type = key_type
end
|
@param name [Symbol] name of this column
@param key_type [Type] type of the keys in the map
@param value_type [Type] type of the values in the map
|
initialize
|
ruby
|
cequel/cequel
|
lib/cequel/schema/column.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/column.rb
|
MIT
|
def cast(value)
value.each_with_object({}) do |(key, element), hash|
hash[@key_type.cast(key)] = @type.cast(element)
end
end
|
@param (see Column#cast)
@return [Hash] hash with keys and values cast to correct type for
column
|
cast
|
ruby
|
cequel/cequel
|
lib/cequel/schema/column.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/column.rb
|
MIT
|
def initialize(keyspace)
@keyspace = keyspace
end
|
@param keyspace [Keyspace] the keyspace whose schema this object
manipulates
@api private
|
initialize
|
ruby
|
cequel/cequel
|
lib/cequel/schema/keyspace.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/keyspace.rb
|
MIT
|
def read_table(name)
TableReader.read(keyspace, name)
end
|
@param name [Symbol] name of the table to read
@return [Table] object representation of the table schema as it
currently exists in the database
|
read_table
|
ruby
|
cequel/cequel
|
lib/cequel/schema/keyspace.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/keyspace.rb
|
MIT
|
def get_table_reader(name)
TableReader.get(keyspace, name)
end
|
@param name [Symbol] name of the table to read
@return [TableReader] object
|
get_table_reader
|
ruby
|
cequel/cequel
|
lib/cequel/schema/keyspace.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/keyspace.rb
|
MIT
|
def create_table(name, &block)
table = TableDescDsl.new(name).eval(&block)
TableWriter.apply(keyspace, table)
end
|
Create a table in the keyspace
@param name [Symbol] name of the new table to create
@yield block evaluated in the context of a {CreateTableDSL}
@return [void]
@example
schema.create_table :posts do
partition_key :blog_subdomain, :text
key :id, :timeuuid
column :title, :text
column :body, :text
column :author_id, :uuid, :index => true
with :caching, :all
end
@see CreateTableDSL
|
create_table
|
ruby
|
cequel/cequel
|
lib/cequel/schema/keyspace.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/keyspace.rb
|
MIT
|
def alter_table(name, &block)
updater = TableUpdater.apply(keyspace, name) do |updater|
UpdateTableDSL.apply(updater, &block)
end
end
|
Make changes to an existing table in the keyspace
@param name [Symbol] the name of the table to alter
@yield block evaluated in the context of an {UpdateTableDSL}
@return [void]
@example
schema.alter_table :posts do
add_set :categories, :text
rename_column :author_id, :author_uuid
create_index :title
end
@see UpdateTableDSL
|
alter_table
|
ruby
|
cequel/cequel
|
lib/cequel/schema/keyspace.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/keyspace.rb
|
MIT
|
def truncate_table(name)
keyspace.execute("TRUNCATE #{name}")
end
|
Remove all data from this table. Truncating a table can be much slower
than simply iterating over its keys and issuing `DELETE` statements,
particularly if the table does not have many rows. Truncating is
equivalent to dropping a table and then recreating it
@param name [Symbol] name of the table to truncate.
@return [void]
|
truncate_table
|
ruby
|
cequel/cequel
|
lib/cequel/schema/keyspace.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/keyspace.rb
|
MIT
|
def drop_table(name, exists: false)
keyspace.execute("DROP TABLE #{'IF EXISTS ' if exists}#{name}")
end
|
Drop this table from the keyspace
@param name [Symbol] name of the table to drop
@param exists [Boolean] if set to true, will drop only if exists (Cassandra 3.x)
@return [void]
|
drop_table
|
ruby
|
cequel/cequel
|
lib/cequel/schema/keyspace.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/keyspace.rb
|
MIT
|
def drop_materialized_view(name, exists: false)
keyspace.execute("DROP MATERIALIZED VIEW #{'IF EXISTS ' if exists}#{name}")
end
|
Drop this materialized view from the keyspace
@param name [Symbol] name of the materialized view to drop
@param exists [Boolean] if set to true, will drop only if exists (Cassandra 3.x)
@return [void]
|
drop_materialized_view
|
ruby
|
cequel/cequel
|
lib/cequel/schema/keyspace.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/keyspace.rb
|
MIT
|
def sync_table(name, &block)
new_table_desc = TableDescDsl.new(name).eval(&block)
patch = if has_table?(name)
existing_table_desc = read_table(name)
TableDiffer.new(existing_table_desc, new_table_desc).call
else
TableWriter.new(new_table_desc) # close enough to a patch
end
patch.statements.each{|stmt| keyspace.execute(stmt) }
end
|
Create or update a table to match a given schema structure. The desired
schema structure is defined by the directives given in the block; this
is then compared to the existing table in the database (if it is
defined at all), and then the table is created or altered accordingly.
@param name [Symbol] name of the table to synchronize
@yield (see #create_table)
@return [void]
@raise (see TableSynchronizer#apply)
@see #create_table Example of DSL usage
|
sync_table
|
ruby
|
cequel/cequel
|
lib/cequel/schema/keyspace.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/keyspace.rb
|
MIT
|
def initialize(synchronizer)
@synchronizer = synchronizer
end
|
@param synchronizer [TableSynchronizer] the synchronizer to validate
|
initialize
|
ruby
|
cequel/cequel
|
lib/cequel/schema/migration_validator.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/migration_validator.rb
|
MIT
|
def validate!
assert_keys_match!
assert_data_columns_match!
end
|
Check for various impossible schema changes and raise if any are found
@raise [InvalidSchemaMigration] if it is impossible to modify existing
table to match desired schema
|
validate!
|
ruby
|
cequel/cequel
|
lib/cequel/schema/migration_validator.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/migration_validator.rb
|
MIT
|
def initialize(name, is_view=false)
@name = name.to_sym
@is_view = is_view
@partition_key_columns, @clustering_columns, @data_columns = [], [], []
@columns, @columns_by_name = [], {}
@properties = ActiveSupport::HashWithIndifferentAccess.new
end
|
@param name [Symbol] the name of the table
@api private
|
initialize
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table.rb
|
MIT
|
def add_column(column_desc)
column_flavor = case column_desc
when PartitionKey
@partition_key_columns
when ClusteringColumn
@clustering_columns
else
@data_columns
end
column_flavor << column_desc
columns << column_desc
columns_by_name[column_desc.name] = column_desc
end
|
Add a column descriptor to this table descriptor.
column_desc - Descriptor of column to add. Can be PartitionKey,
ClusteringColumn, DataColumn, List, Set, or Map.
|
add_column
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table.rb
|
MIT
|
def add_property(property_desc)
properties[property_desc.name] = property_desc
end
|
Add a property to this table descriptor
property_desc - A `TableProperty` describing one property of this table.
|
add_property
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table.rb
|
MIT
|
def key_columns
partition_key_columns + clustering_columns
end
|
@return [Array<Column>] all key columns (partition + clustering)
|
key_columns
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table.rb
|
MIT
|
def key_column_names
key_columns.map { |key| key.name }
end
|
@return [Array<Symbol>] names of all key columns (partition +
clustering)
|
key_column_names
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table.rb
|
MIT
|
def partition_key_column_names
partition_key_columns.map { |key| key.name }
end
|
@return [Array<Symbol>] names of partition key columns
|
partition_key_column_names
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table.rb
|
MIT
|
def clustering_column_names
clustering_columns.map { |key| key.name }
end
|
@return [Array<Symbol>] names of clustering columns
|
clustering_column_names
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table.rb
|
MIT
|
def partition_key(name)
partition_key_columns.find { |column| column.name == name }
end
|
@param name [Symbol] name of partition key column to look up
@return [PartitionKey] partition key column with given name
|
partition_key
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table.rb
|
MIT
|
def clustering_column(name)
clustering_columns.find { |column| column.name == name }
end
|
@param name [Symbol] name of clustering column to look up
@return [ClusteringColumn] clustering column with given name
|
clustering_column
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table.rb
|
MIT
|
def data_column(name)
name = name.to_sym
data_columns.find { |column| column.name == name }
end
|
@param name [Symbol] name of data column to look up
@return [DataColumn,CollectionColumn] data column or collection column
with given name
|
data_column
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table.rb
|
MIT
|
def property(name)
properties.fetch(name, null_table_property).value
end
|
@param name [Symbol] name of property to look up
@return [TableProperty] property as defined on table
|
property
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table.rb
|
MIT
|
def eval(&desc_block)
instance_eval(&desc_block)
table
end
|
Returns a Table object built by evaluating the provided block.
Yields nothing but block is instance_evaled so it as access to
all the methods of the instance.
|
eval
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table_desc_dsl.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table_desc_dsl.rb
|
MIT
|
def partition_key(name, type)
columns << PartitionKey.new(name, type(type))
end
|
Describe (one of) the partition key(s) of the table.
name - The name of the column.
type - The type of the column. Either a `Cequel::Type` or a symbol.
See `Cequel::Type`.
|
partition_key
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table_desc_dsl.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table_desc_dsl.rb
|
MIT
|
def key(name, type, clustering_order = nil)
columns << if has_partition_key?
ClusteringColumn.new(name, type(type), clustering_order)
else
(fail ArgumentError, "Can't set clustering order for partition key #{name}") if clustering_order
PartitionKey.new(name, type(type))
end
end
|
Describe (one of) the key(s) of the table.
name - The name of the column
type - The type of the column. Either a `Cequel::Type` or a symbol.
See `Cequel::Type`.
clustering_order - `:asc` or `:desc`. Only meaningful for cluster
keys. Leave nil for partition keys.
|
key
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table_desc_dsl.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table_desc_dsl.rb
|
MIT
|
def column(name, type, options = {})
columns << DataColumn.new(name, type(type),
figure_index_name(name, options.fetch(:index, nil)))
end
|
Describe a column of the table
name - The name of the column.
type - The type of the column. Either a `Cequel::Type` or a symbol.
See `Cequel::Type`.
options
:index - name of a secondary index to apply to the column, or
`true` to infer an index name by convention
|
column
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table_desc_dsl.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table_desc_dsl.rb
|
MIT
|
def list(name, type)
columns << List.new(name, type(type))
end
|
Describe a column of type list.
name - The name of the column.
type - The type of the elements of this column. Either a
`Cequel::Type` or a symbol. See `Cequel::Type`.
|
list
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table_desc_dsl.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table_desc_dsl.rb
|
MIT
|
def set(name, type)
columns << Set.new(name, type(type))
end
|
Describe a column of type set.
name - The name of the column.
type - The type of the members of this column. Either a
`Cequel::Type` or a symbol. See `Cequel::Type`.
|
set
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table_desc_dsl.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table_desc_dsl.rb
|
MIT
|
def map(name, key_type, value_type)
columns << Map.new(name, type(key_type), type(value_type))
end
|
Describe a column of type map.
name - The name of the column.
key_type - The type of the keys of this column. Either a
`Cequel::Type` or a symbol. See `Cequel::Type`.
value_type - The type of the values of this column. Either a
`Cequel::Type` or a symbol. See `Cequel::Type`.
|
map
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table_desc_dsl.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table_desc_dsl.rb
|
MIT
|
def compact_storage
@is_compact_storage = true
end
|
Direct that this table use "compact storage". This is primarily useful
for backwards compatibility with legacy CQL2 table schemas.
@return [void]
|
compact_storage
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table_desc_dsl.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table_desc_dsl.rb
|
MIT
|
def materialized_view
self.is_view = true
end
|
Indicates that this is a materialized view.
@return [void]
|
materialized_view
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table_desc_dsl.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table_desc_dsl.rb
|
MIT
|
def call
(fail InvalidSchemaMigration, "Table renames are not supported") if
table_a.name != table_b.name
(fail InvalidSchemaMigration, "Changes to key structure is not allowed") if
keys_changed?
(fail InvalidSchemaMigration, "Type changes are not allowed") if any_types_changed?
Patch.new(figure_changes)
end
|
Returns a Patch that will transform table_a in to table_b.
|
call
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table_differ.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table_differ.rb
|
MIT
|
def initialize(name, value)
@name = name
self.normalized_value = value
end
|
@param name [Symbol] name of the property
@param value value of the property
|
initialize
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table_property.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table_property.rb
|
MIT
|
def to_cql
"#{@name} = #{value_cql}"
end
|
@return [String] CQL fragment defining this property in a `CREATE
TABLE` statement
|
to_cql
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table_property.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table_property.rb
|
MIT
|
def hash
[name, value].hash
end
|
Returns a hash code for this object
|
hash
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table_property.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table_property.rb
|
MIT
|
def read(keyspace, table_name)
table_data = fetch_raw_keyspace(keyspace).table(table_name.to_s)
(fail NoSuchTableError) if table_data.blank?
new(table_data).call
end
|
Read the schema defined in the database for a given table and return a
{Table} instance
@param (see #initialize)
@return (see #read)
|
read
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table_reader.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table_reader.rb
|
MIT
|
def initialize(table_data)
@table_data = table_data
@table = Table.new(table_data.name,
Cassandra::MaterializedView === table_data)
end
|
@param keyspace [Metal::Keyspace] keyspace to read the table from
@param table_name [Symbol] name of the table to read
@private
|
initialize
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table_reader.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table_reader.rb
|
MIT
|
def call
return nil if table_data.blank?
read_partition_keys
read_clustering_columns
read_indexes
read_data_columns
read_properties
read_table_settings
table
end
|
Read table schema from the database
@return [Table] object representation of table in the database, or
`nil` if no table by given name exists
@api private
|
call
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table_reader.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table_reader.rb
|
MIT
|
def initialize(keyspace, table_name)
@keyspace, @table_name = keyspace, table_name
@statements = []
end
|
@param keyspace [Metal::Keyspace] keyspace containing the table
@param table_name [Symbol] name of the table to modify
@private
|
initialize
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table_updater.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table_updater.rb
|
MIT
|
def apply
statements.each { |statement| keyspace.execute(statement) }
end
|
Apply the schema modifications to the table schema in the database
@return [void]
@api private
|
apply
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table_updater.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table_updater.rb
|
MIT
|
def add_column(name, type)
add_data_column(Column.new(name, type(type)))
end
|
Add a column to the table
@param name [Symbol] the name of the column
@param type [Symbol,Type] the type of the column
@return [void]
|
add_column
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table_updater.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table_updater.rb
|
MIT
|
def add_list(name, type)
add_data_column(List.new(name, type(type)))
end
|
Add a list to the table
@param name [Symbol] the name of the list
@param type [Symbol,Type] the type of the list elements
@return [void]
|
add_list
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table_updater.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table_updater.rb
|
MIT
|
def add_set(name, type)
add_data_column(Set.new(name, type(type)))
end
|
Add a set to the table
@param name [Symbol] the name of the set
@param type [Symbol,Type] the type of the set elements
@return [void]
|
add_set
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table_updater.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table_updater.rb
|
MIT
|
def add_map(name, key_type, value_type)
add_data_column(Map.new(name, type(key_type), type(value_type)))
end
|
Add a map to the table
@param name [Symbol] the name of the map
@param key_type [Symbol,Type] the type of the map's keys
@param value_type [Symbol,Type] the type of the map's values
@return [void]
|
add_map
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table_updater.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table_updater.rb
|
MIT
|
def rename_column(old_name, new_name)
add_stmt %Q|ALTER TABLE "#{table_name}" RENAME "#{old_name}" TO "#{new_name}"|
end
|
Rename a column
@param old_name [Symbol] the current name of the column
@param new_name [Symbol] the new name of the column
@return [void]
|
rename_column
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table_updater.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table_updater.rb
|
MIT
|
def drop_column(name)
add_stmt %Q|ALTER TABLE "#{table_name}" DROP "#{name}"|
end
|
Remove a column
@param name [Symbol] the name of the column to remove
@return [void]
|
drop_column
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table_updater.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table_updater.rb
|
MIT
|
def change_properties(options)
properties = options
.map { |name, value| TableProperty.build(name, value).to_cql }
add_stmt %Q|ALTER TABLE "#{table_name}" WITH #{properties.join(' AND ')}|
end
|
Change one or more table storage properties
@param options [Hash] map of property names to new values
@return [void]
@see Table#add_property
|
change_properties
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table_updater.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table_updater.rb
|
MIT
|
def create_index(column_name, index_name = "#{table_name}_#{column_name}_idx")
add_stmt %Q|CREATE INDEX "#{index_name}" ON "#{table_name}" ("#{column_name}")|
end
|
Create a secondary index
@param column_name [Symbol] name of the column to add an index on
@param index_name [Symbol] name of the index; will be inferred from
convention if nil
@return [void]
|
create_index
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table_updater.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table_updater.rb
|
MIT
|
def drop_index(index_name)
add_stmt %Q|DROP INDEX IF EXISTS "#{index_name}"|
end
|
Remove a secondary index
@param index_name [Symbol] the name of the index to remove
@return [void]
|
drop_index
|
ruby
|
cequel/cequel
|
lib/cequel/schema/table_updater.rb
|
https://github.com/cequel/cequel/blob/master/lib/cequel/schema/table_updater.rb
|
MIT
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.