Module: Cequel::Record

Extended by:
ActiveSupport::Concern, Util::Forwardable
Defined in:
lib/cequel/record.rb,
lib/cequel/record/bound.rb,
lib/cequel/record/dirty.rb,
lib/cequel/record/errors.rb,
lib/cequel/record/schema.rb,
lib/cequel/record/scoped.rb,
lib/cequel/record/finders.rb,
lib/cequel/record/railtie.rb,
lib/cequel/record/callbacks.rb,
lib/cequel/record/collection.rb,
lib/cequel/record/conversion.rb,
lib/cequel/record/properties.rb,
lib/cequel/record/record_set.rb,
lib/cequel/record/timestamps.rb,
lib/cequel/record/bulk_writes.rb,
lib/cequel/record/persistence.rb,
lib/cequel/record/validations.rb,
lib/cequel/record/associations.rb,
lib/cequel/record/mass_assignment.rb,
lib/cequel/record/data_set_builder.rb,
lib/cequel/record/record_generator.rb,
lib/cequel/record/has_many_association.rb,
lib/cequel/record/association_collection.rb,
lib/cequel/record/belongs_to_association.rb,
lib/cequel/record/lazy_record_collection.rb,
lib/cequel/record/configuration_generator.rb

Overview

Cequel::Record is an active record-style data modeling library and object-row mapper. Model classes inherit from Cequel::Record, define their columns in the class definition, and have access to a full and robust set of read and write functionality.

Individual components are documented in their respective modules. See below for links.

Examples:

A Record class showing off many of the possibilities

class Post
  include Cequel::Record

  belongs_to :blog
  key :id, :timeuuid, auto: true
  column :title, :text
  column :body, :text
  column :author_id, :uuid, index: true
  set :categories

  has_many :comments, dependent: destroy

  after_create :notify_followers

  validates :title, presence: true

  def self.for_author(author_id)
    where(:author_id, author_id)
  end
end

See Also:

Defined Under Namespace

Modules: Associations, BulkWrites, Callback, Callbacks, ClassMethods, Collection, Conversion, Dirty, Finders, MassAssignment, Persistence, Properties, Schema, Scoped, Timestamps, Validations Classes: AssociationCollection, BelongsToAssociation, Bound, ClusteringColumnBound, ConfigurationGenerator, DataSetBuilder, HasManyAssociation, LazyRecordCollection, List, Map, PartitionKeyBound, Railtie, RecordGenerator, RecordSet, Set, TimeuuidBound

Constant Summary collapse

MissingAttributeError =

Raised when attempting to access an attribute of a record when that attribute hasn’t been loaded

Since:

  • 1.0.0

Class.new(ArgumentError)
UnknownAttributeError =

Raised when attempting to read or write an attribute that isn’t defined on the record

Since:

  • 1.0.0

Class.new(ArgumentError)
RecordNotFound =

Raised when attempting to load a record by key when that record does not exist

Class.new(StandardError)
InvalidRecordConfiguration =

Raised when attempting to configure a record in a way that is not possible

Since:

  • 1.0.0

Class.new(StandardError)
RecordInvalid =

Raised when attempting to save a record that is invalid

Class.new(StandardError)
IllegalQuery =

Raised when attempting to construct a RecordSet that cannot construct a valid CQL query

Since:

  • 1.0.0

Class.new(StandardError)
DangerousQueryError =

Raised when attempting to perform a query that has detrimental effects. Typically when trying to count records.

Class.new(StandardError)
MissingKeyError =

Raised when attempting to persist a Cequel::Record without defining all primary key columns

Since:

  • 1.0.0

Class.new(StandardError)
MissingTableNameError =

Raised when attempting to reflect on the schema of a Cequel::Record without a table name.

Class.new(StandardError)

Class Attribute Summary collapse

Class Method Summary collapse

Methods included from Util::Forwardable

delegate

Class Attribute Details

.connectionMetal::Keyspace

Returns the keyspace used for record persistence.

Returns:



109
110
111
# File 'lib/cequel/record.rb', line 109

def connection
  @connection
end

Class Method Details

.descendantsArray<Class>

Returns All the record classes that are currently defined.

Returns:

  • (Array<Class>)

    All the record classes that are currently defined.



124
125
126
127
128
129
130
131
132
# File 'lib/cequel/record.rb', line 124

def descendants
  weak_descendants.map do |clazz|
    begin
      clazz.__getobj__ if clazz.weakref_alive?
    rescue WeakRef::RefError
      nil
    end
  end.compact
end

.establish_connection(configuration) ⇒ void

This method returns an undefined value.

Establish a connection with the given configuration

Parameters:

  • configuration (Options)

Options Hash (configuration):

  • :host (String) — default: '127.0.0.1'

    hostname of single Cassandra instance to connect to

  • :port (Integer) — default: 9042

    port on which to connect to all specified hosts

  • :max_retries (Integer)

    maximum number of retries on connection failure

  • :hosts (Array<String>)

    list of Cassandra instances to connect to (hostnames only)

  • :username (String)

    user to auth with (leave blank for no auth)

  • :password (String)

    password to auth with (leave blank for no auth)

  • :keyspace (String)

    name of keyspace to connect to

  • :ssl (Boolean)

    enable/disable ssl/tls support

  • :server_cert (String)

    path to ssl server certificate

  • :client_cert (String)

    path to ssl client certificate

  • :private_key (String)

    path to ssl client private key

  • :passphrase (String)

    the passphrase for client private key

  • :cassandra_error_policy (String)

    A mixin for handling errors from Cassandra

  • :cassandra_options (Hash)

    A hash of arbitrary options to pass to Cassandra



118
119
120
# File 'lib/cequel/record.rb', line 118

def establish_connection(configuration)
  self.connection = Cequel.connect(configuration)
end

.included(base) ⇒ Object

Hook called when new record classes are created.



135
136
137
# File 'lib/cequel/record.rb', line 135

def included(base)
  weak_descendants << WeakRef.new(base)
end