项目作者: conradwt

项目描述 :
Cassandra Example Using Rails
高级语言: Ruby
项目地址: git://github.com/conradwt/cassandra-example-using-rails.git
创建时间: 2014-09-20T09:28:42Z
项目社区:https://github.com/conradwt/cassandra-example-using-rails

开源协议:MIT License

下载


Cassandra Example Using Ruby

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.

Requirements

  • Docker Desktop 4.23.0 or newer

  • Rails >= 5.2.8.1 and < 6

  • Ruby >= 2.7.8 and < 3

Note: This tutorial was updated on macOS 13.5.2.

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. Create the project directory

    1. mkdir blog
    2. cd blog
  3. Create docker-compose.yml file with the following content:

    1. services:
    2. some-cassandra:
    3. image: cassandra:4.1.3
    4. container_name: some-cassandra
    5. environment:
    6. - CASSANDRA_CLUSTER_NAME=cassandra-cluster
    7. ports:
    8. - 9042:9042
    9. volumes:
    10. - cassandra-data:/var/lib/cassandra
    11. volumes:
    12. cassandra-data: {}
  4. Start a single node cluster

    1. docker-compose up -d
  5. Check the status of your cluster

    1. docker-compose exec some-cassandra nodetool status

    Note: One should see that the node status as Up Normal (UN) that looks similar to the following:

    1. Datacenter: datacenter1
    2. =======================
    3. Status=Up/Down
    4. |/ State=Normal/Leaving/Joining/Moving
    5. -- Address Load Tokens Owns Host ID Rack
    6. UN 172.19.0.2 582.5 KB 256 ? e61cf276-c860-4990-bf03-37161414aed2 rack1
    7. Note: Non-system keyspaces don't have the same replication settings, effective ownership information is meaningless
  6. Generate a new Rails application

    1. gem install rails -v '5.2.8.1'
    2. rails _5.2.8.1_ new . ---skip-active-record --skip-active-storage -T --skip-bundle --skip-webpack-install --skip-javascript --no-rc
  7. Add the Ruby cequel gem

    1. bundle add i18n --version "= 1.8.11"
    2. bundle add cequel
    3. bundle add activemodel-serializers-xml
  8. Generate scaffold of the application

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

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

    1. class Post
    2. include Cequel::Record
    3. key :id, :timeuuid, auto: true
    4. column :title, :text
    5. column :body, :text
    6. timestamps
    7. end
  11. Create a default Cassandra configuration file

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

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

    1. rails cequel:migrate
  14. Start the Rails server

    1. rails s
  15. Play with the application

    1. open http://localhost:3000
  16. Remove the keyspace

    1. rails cequel:keyspace:drop
  17. Stop a single node cluster

    1. docker-compose down

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 2014 - 2023 Conrad Taylor. All Rights Reserved.