Class: Cequel::Record::OrmAdapter

Inherits:
OrmAdapter::Base
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/cequel/record/orm_adapter.rb

Overview

ORM adapter for Cequel, the Ruby ORM for Cassandra

Instance Method Summary collapse

Instance Method Details

#column_namesArray<Symbol>

Returns names of columns on this model.

Returns:

  • (Array<Symbol>)

    names of columns on this model



19
20
21
# File 'lib/cequel/record/orm_adapter.rb', line 19

def column_names
  klass.columns.map { |column| column.name }
end

#create!(attributes = {}) ⇒ Cequel::Record

Create a new instance of the record class and save it to the database

Parameters:

  • attributes (Hash) (defaults to: {})

    map of column names to values

Returns:

Raises:

  • (Cequel::Record::RecordInvalid)

    if the record fails validations



87
# File 'lib/cequel/record/orm_adapter.rb', line 87

def_delegator :klass, :create!

#destroy(record) ⇒ void

This method returns an undefined value.

Destroy the given record

Parameters:



95
96
97
# File 'lib/cequel/record/orm_adapter.rb', line 95

def destroy(record)
  record.destroy
end

#find_all(options = {}) ⇒ Array<Cequel::Record>

Find all records with the given conditions and limit

Parameters:

  • options (Options) (defaults to: {})

    options for query

Options Hash (options):

  • :conditions (Hash)

    map of column names to column values. This can either be a one-element hash specifying a secondary index lookup, or a mapping of primary key columns to values.

  • :limit (Integer)

    maximum number of rows to return

Returns:



74
75
76
# File 'lib/cequel/record/orm_adapter.rb', line 74

def find_all(options = {})
  construct_scope(options).to_a
end

#find_first(options = {}) ⇒ Cequel::Record

Find the first record instance with the given conditions

Parameters:

  • options (Options) (defaults to: {})

    options for query

Options Hash (options):

  • :conditions (Hash)

    map of column names to column values. This can either be a one-element hash specifying a secondary index lookup, or a mapping of primary key columns to values.

Returns:

  • (Cequel::Record)

    the first record matching the query, or nil if none present



60
61
62
# File 'lib/cequel/record/orm_adapter.rb', line 60

def find_first(options = {})
  construct_scope(options).first
end

#get(key_values) ⇒ Cequel::Record

Returns a record instance corresponding to this primary key or nil if not present.

Parameters:

  • key_values (Array)

    values for each primary key column on this record

Returns:

  • (Cequel::Record)

    a record instance corresponding to this primary key or nil if not present

See Also:



44
45
46
47
48
# File 'lib/cequel/record/orm_adapter.rb', line 44

def get(key_values)
  get!(key_values)
rescue Cequel::Record::RecordNotFound
  nil
end

#get!(key_values) ⇒ Cequel::Record

Returns a record instance corresponding to this primary key.

Parameters:

  • key_values (Array)

    values for each primary key column on this record

Returns:

  • (Cequel::Record)

    a record instance corresponding to this primary key

Raises:

  • (Cequel::Record::RecordNotFound)

    if the key is not present

See Also:



32
33
34
# File 'lib/cequel/record/orm_adapter.rb', line 32

def get!(key_values)
  klass.find(*key_values)
end