Sha256: 17a8edbc12fd2de4180de7fb6ab4b93fc983311d37030aac5b8886f572d19f07

Contents?: true

Size: 1.86 KB

Versions: 12

Compression:

Stored size: 1.86 KB

Contents

# Superstore
[![Build Status](https://secure.travis-ci.org/data-axle/superstore.png?rvm=2.0.0)](http://travis-ci.org/data-axle/superstore) [![Code Climate](https://codeclimate.com/github/data-axle/superstore.png)](https://codeclimate.com/github/data-axle/superstore)

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

## Installation

Add the following to your Gemfile:
```ruby
gem 'superstore'
```

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

## Defining Models

```ruby
class Widget < Superstore::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:

```ruby
gem 'cassandra-cql'
```
  
Add a config/superstore.yml:

```yaml
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:

```ruby
gem 'pg'
```
  
And a config/superstore.yml:

```yaml
development:
  adapter: hstore
```

## Creating and updating records

Cassandra Object has equivalent methods as ActiveRecord:

```ruby
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

```ruby
widget = Widget.find(uuid)
widget = Widget.first
widgets = Widget.all
Widget.find_each do |widget|
  # Codez
end
```

## Scoping

Some lightweight scoping features are available:
```ruby
  Widget.where('color' => 'red')
  Widget.select(['name', 'color'])
  Widget.limit(10)
```

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
superstore-1.0.12 README.md
superstore-1.0.11 README.md
superstore-1.0.10 README.md
superstore-1.0.9 README.md
superstore-1.0.8 README.md
superstore-1.0.7 README.md
superstore-1.0.6 README.md
superstore-1.0.5 README.md
superstore-1.0.4 README.md
superstore-1.0.3 README.md
superstore-1.0.2 README.md
superstore-1.0.0 README.md