Sha256: 154b5c9c1054d6eaf789859fa9250532344e3a08bb2f4ad7bd4bf535bccc932a

Contents?: true

Size: 1.21 KB

Versions: 6

Compression:

Stored size: 1.21 KB

Contents

== Cassandra Object

Cassandra Object uses ActiveModel to mimic much of the behavior in ActiveRecord.

== Installation

Add the following to your Gemfile:

  gem 'gotime-cassandra_object'

== Defining Models

  class Widget < CassandraObject::Base
    key :uuid
    string :name
    string :description
    integer :price
    array :colors, unique: true

    validates :name, presence: :true

    before_create do
      self.description = "#{name} is the best product ever"
    end
  end

== Connecting to the Server

  CassandraObject::Base.establish_connection(
    keyspace: 'my_app_development',
    servers: '127.0.0.1:9160',
    thrift: {
      timeout: 20
      retries: 2
    }
  )

== Creating and updating records

Cassandra Object has equivalent methods as ActiveRecord:

  widget = Widget.new
  widget.valid?
  widget = Widget.create(name: 'Acme', price: 100)
  widget.update_attribute(:price, 1200)
  widget.update_attributes(price: 1200, name: 'Acme Corporation')
  widget.attributes = {price: 300}
  widget.price_was
  widget.save
  widget.save!

== Finding records

  widget = Widget.find(uuid)
  widget = Widget.first
  widgets = Widget.all
  Widget.find_each do |widget|
    ...
  end

CQL is currently not supported

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
gotime-cassandra_object-2.7.0 README.rdoc
gotime-cassandra_object-2.6.4 README.rdoc
gotime-cassandra_object-2.6.3 README.rdoc
gotime-cassandra_object-2.6.2 README.rdoc
gotime-cassandra_object-2.6.1 README.rdoc
gotime-cassandra_object-2.6.0 README.rdoc