-
Notifications
You must be signed in to change notification settings - Fork 28
Rails Integration (Experimental)
Below is a list of steps to configure and use Diametric from inside of Rails.
-
Create a Rails app using the
--skip-active-record
option.> rails new rails-sample --skip-active-record
-
Add diametric to your Gemfile
# Gemfile gem 'diametric'
-
Bundle it up!
> bundle
-
Create a config file
diametric:config
taskMake 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]
If you haven't downloaded Datomic yet, get it by the command below.
> bundle exec download-datomic
> bundle exec datomic-rest -p 9000 -a free -u datomic:mem://
-
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
-
Create* model schema
> rake diametric:create_schema
* Transact in Datomic lingo.
-
Create controllers and views
> rails g scaffold post name:string content:text
-
Start rails, and visit http://localhost:3000/posts
Voila!
When you want to use Datomic's free transactor to save data to a file:
-
Start Datomic transactor (see the section "Running the transactor with the free storage protocol")
-
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]
. -
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
-
Start Rails
[no bug reported at this moment]