Git Product home page Git Product logo

nshbrown / active_column Goto Github PK

View Code? Open in Web Editor NEW

This project forked from carbonfive/active_column

1.0 2.0 0.0 222 KB

ActiveColumn is a data management framework for Cassandra. It includes data migrations similar to ActiveRecord, and a data mapping framework for "time line" modeled data.

Home Page: http://blog.carbonfive.com/2011/01/06/database-migrations-for-cassandra-with-activecolumn/

Ruby 100.00%

active_column's Introduction

IMPORTANT: If you are reading this on the main ActiveColumn page on github, please go to the actual README page so that links bring you to the right place.

ActiveColumn

ActiveColumn is a framework for working with data in Cassandra. It currently includes two features:

  • Database migrations
  • "Time line" model data management

Data migrations are very similar to those in ActiveRecord, and are documented in Migrate.

Time line data management is loosely based on concepts in ActiveRecord, but is adapted to saving data in which rows in Cassandra grow indefinitely over time, such as in the oft-used Twitter example for Cassandra. This usage is documented in:

Installation

Add ActiveColumn to your Gemfile:

gem 'active_column'

Install with bundler:

bundle install

Usage

Configuration

ActiveColumn requires Cassandra 0.7 or above, as well as the cassandra gem, version 0.9 or above. You must also be sure to use the Cassandra 0.7 support in the gem, which can be done by adding Cassandra to your Gemfile like this:

gem 'cassandra', '>= 0.9', :require => 'cassandra/0.7'

Data migrations in ActiveColumn are used within a Rails project, and are driven off of a configuration file, config/cassandra.yml. It should look something like this:

config/cassandra.yml

test:
  servers: "127.0.0.1:9160"
  keyspace: "myapp_test"
  thrift:
    timeout: 3
    retries: 2

development:
  servers: "127.0.0.1:9160"
  keyspace: "myapp_development"
  thrift:
    timeout: 3
    retries: 2

You can use embedded ruby code in the YAML file to determine host/machine specific settings.

  production:
    servers: "<%=get_from_file('abc.conf')%>:9160"
    keyspace: "<%=get_from_file('abc.conf')%>"
    disable_node_auto_discovery: true
    thrift:
      timeout: 3
      retries: 2

Node Auto Discovery

You can set disable_node_auto_discovery to off by setting disable_node_auto_discovery flag in your cassandra.yml

In order to get time line modeling support, you must provide ActiveColumn with an instance of a Cassandra object. Since you have your cassandra.yml from above, you can do this very simply like this:

config/initializers/cassandra.rb

config = YAML.load_file(Rails.root.join("config", "cassandra.yml"))[Rails.env]
$cassandra = Cassandra.new(config['keyspace'],
                           config['servers'],
                           config['thrift'])

ActiveColumn.connection = $cassandra

As you can see, I create a global $cassandra variable, which I use in my tests to validate data directly in Cassandra.

Examples

Add column family

  create_column_family :impressions do |cf|
    cf.comment = 'impressions for something'
    cf.comparator_type = :utf8 
    cf.key_validation_class = :utf8 
  end

Drop column family

  drop_column_family :impressions

Rename column family

  rename_column_family :impressions, :showings

Update column family

  update_column_family :impressions do |cf|
    cf.comment = "blah"
    cf.gc_grace_seconds = 3600
  end

One other thing to note is that you obviously must have Cassandra installed and running! Please take a look at the mama_cass gem for a quick way to get up and running with Cassandra for development and testing.

active_column's People

Contributors

karlfreeman avatar kevinrood avatar mwynholds avatar nshbrown avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.