Code Monkey home page Code Monkey logo

cassandra_object's Introduction

Cassandra Object

Build Status Code Climate

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

Installation

Add the following to your Gemfile:

gem 'gotime-cassandra_object'

Change the version of Cassandra accordingly. Recent versions have not been backward compatible.

Defining Models

class Widget < CassandraObject::Base
  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

Using with Cassandra

Add the cassandra-cql gem to Gemfile:

gem 'cassandra-cql'

Add a config/cassandra.yml:

development:
  adapter: cassandra
  keyspace: my_app_development
  servers: ["127.0.0.1:9160"]
  thrift:
    timeout: 20
    retries: 2

Using with Postgres HStore

Add the pg gem to your Gemfile:

gem 'pg'

And a config/cassandra.yml:

development:
  adapter: hstore

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|
  # Codez
end

Scoping

Some lightweight scoping features are available:

  Widget.where('color' => 'red')
  Widget.select(['name', 'color'])
  Widget.limit(10)

cassandra_object's People

Contributors

matthuhiggins avatar nzkoz avatar grantr avatar ryanking avatar jamesgolick avatar kadwanev avatar forresty avatar josh avatar tomafro avatar human-spider avatar ebarendt avatar jmhodges avatar doolin avatar silviorelli avatar

Watchers

 avatar James Cloos avatar

Forkers

giovannelli

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.