cassandra-example-using-ruby icon indicating copy to clipboard operation
cassandra-example-using-ruby copied to clipboard

The purpose of this step-by-step tutorial is to provide a very simple example of configuring and using the Cassandra database engine with the Ruby Language.

Cassandra Example Using Ruby

The purpose of this step by step tutorial is to provide a very simple example of configuring and using Cassandra database engine with the Ruby Language.

Requirements

  • Cassandra 4.0.1 or newer

  • OpenJDK >= 11.0.11 and < 12

  • Node 14.18.2 or newer

  • Rails 6.1.6 or newer

  • Ruby 3.1.2 or newer

  • Yarn 1.22.18 or newer

Note: This tutorial was updated on macOS 12.3.1.

Communication

  • If you need help, use Stack Overflow. (Tag 'cassandra')
  • If you'd like to ask a general question, use Stack Overflow.
  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.

Installation, Setup, and Usage

  1. Open new terminal window

  2. Download Cassandra

    cd
    wget https://downloads.apache.org/cassandra/4.0.1/apache-cassandra-4.0.1-bin.tar.gz
    
  3. Installing Cassandra

    cd
    gzip -dc apache-cassandra-4.0.1-bin.tar.gz | tar xf -
    
  4. In the terminal, perform the following:

    export CASSANDRA_VERSION=4.0.1
    export CASSANDRA_HOME=${HOME}/apache-cassandra-${CASSANDRA_VERSION}
    export PATH=${CASSANDRA_HOME}/bin:${PATH}
    
  5. Start Cassandra

    cassandra -f
    
  6. Open another terminal window

  7. Generate a new Rails application

    rails new blog ---skip-active-record --skip-active-storage -T --skip-bundle --skip-webpack-install --skip-javascript
    
  8. Add Ruby gems

    cd blog
    bundle add cequel
    bundle add activemodel-serializers-xml
    bundle add sorted_set
    
  9. Generate scaffold of the application

    rails g scaffold post title body
    
  10. Add the following as the first route within config/routes.rb file:

    root 'posts#index'
    
  11. Create app/models/post.rb file with the following content:

    class Post
      include Cequel::Record
    
      key :id, :timeuuid, auto: true
      column :title, :text
      column :body, :text
    
      timestamps
    end
    
  12. Create a default Cassandra configuration file

    rails g cequel:configuration
    
  13. Initialize Cassandra keyspace (database)

    rails cequel:keyspace:create
    
  14. Synchronize your Rails model schemas with Cassandra keyspace

    rails cequel:migrate
    
  15. Start the Rails server

    rails s
    
  16. Play with the application

    open http://localhost:3000
    

References

Support

Bug reports and feature requests can be filed for the cassandra-example-using-rails project here:

Contact

Follow Conrad Taylor on Twitter (@conradwt)

Creator

License

This repository is released under the MIT License.

Copyright

© Copyright 2014 - 2021 Conrad Taylor. All Rights Reserved.