Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Rails Integration (Experimental)

yokolet edited this page · 19 revisions

Below is a list of steps to configure and use Diametric from inside of Rails.

  1. Create a Rails app using the --skip-active-record option.

    > rails new rails-sample --skip-active-record
    
  2. Add diametric to your Gemfile

    # Gemfile
    gem 'diametric'
    
  3. Bundle it up!

    > bundle
    
  4. Create a config file diametric:config task

    Make sure there's no space between config arguments.

    # For a REST connection
    > bundle exec rake "diametric:config[REST,sample,9000,free]"
    
    # For a Peer connection
    > rake diametric:config[PEER,sample]
    

    Download Datomic

    If you haven't downloaded Datomic yet, get it by the command below.

    > bundle exec download-datomic
    

    Start the Datomic REST service (if using a REST connection)

    > bundle exec datomic-rest -p 9000 -a free -u datomic:mem://
    
  5. Create some model(s)

    For example, create app/models/post.rb:

    class Post
      include Diametric::Entity
      include Diametric::Persistence::REST
      # include Diametric::Persistence::Peer
    
      attribute :name, String, :index => true
      attribute :content, String
    end
  6. Create* model schema

    > rake diametric:create_schema
    

    * Transact in Datomic lingo.

  7. Create controllers and views

    > rails g scaffold post name:string content:text
    
  8. Start rails, and visit http://localhost:3000/posts

    Voila!

Free Transactor Setup (only on JRuby)

When you want to use Datomic's free transactor to save data to a file:

  1. Start Datomic transactor (see the section "Running the transactor with the free storage protocol")

  2. Delete config/diametric.yml and re-create it

    > bundle exec rake diametric:config[FREE,<your db name>,<port>]
    

    for example, diametric:config[FREE,sample,4334].

  3. Create config/initializers/diametric.rb

    pathname = Rails.root.join("config", "diametric.yml")
    if pathname.file?
      require 'yaml'
      config = YAML.load(pathname.read)
      uri = config["development"]["uri"]
      Diametric::Persistence::Peer.create_database(uri)
      Diametric::Persistence::Peer.connect(uri)
    end
  4. Start Rails

Known Bugs

[no bug reported at this moment]

Something went wrong with that request. Please try again.