cassandra-example-using-ruby
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
-
Open new terminal window
-
Download Cassandra
cd wget https://downloads.apache.org/cassandra/4.0.1/apache-cassandra-4.0.1-bin.tar.gz
-
Installing Cassandra
cd gzip -dc apache-cassandra-4.0.1-bin.tar.gz | tar xf -
-
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}
-
Start Cassandra
cassandra -f
-
Open another terminal window
-
Generate a new Rails application
rails new blog ---skip-active-record --skip-active-storage -T --skip-bundle --skip-webpack-install --skip-javascript
-
Add Ruby gems
cd blog bundle add cequel bundle add activemodel-serializers-xml bundle add sorted_set
-
Generate scaffold of the application
rails g scaffold post title body
-
Add the following as the first route within config/routes.rb file:
root 'posts#index'
-
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
-
Create a default Cassandra configuration file
rails g cequel:configuration
-
Initialize Cassandra keyspace (database)
rails cequel:keyspace:create
-
Synchronize your Rails model schemas with Cassandra keyspace
rails cequel:migrate
-
Start the Rails server
rails s
-
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.