Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make project easily integrate with Rails. #20

Open
avescodes opened this issue Nov 14, 2012 · 14 comments
Open

Make project easily integrate with Rails. #20

avescodes opened this issue Nov 14, 2012 · 14 comments
Assignees

Comments

@avescodes
Copy link
Contributor

A few basic features I want to add:

  • Including diametric in a Gemfile will automatically connect on rails boot (if config/diametric.yml is present)
  • A generator diametric:install should exist, so when i say: rails g diametric:install I get a sample config/diametric.yml to populate with my own connection data
  • I can still declare: connect(...some new interface...) in my models to override the datomic instance in which my model connects to.

Nice to have:

  • Override model generators to generate Diametric entities.
@ghost ghost assigned avescodes Nov 14, 2012
@yokolet
Copy link
Contributor

yokolet commented Nov 14, 2012

I agree with Rails integration is important since it is a Ruby gem.

Here're considerations came upon in my mind.

Gem specific setting should go to config/initializers/diametric.rb . All files here wil be loaded during Rails initialization.
For example:

Diametric.config do |config|
    config.uri = "datomic:mem://hello"
    config.port = 9000
end

If there's a port in config, a connection should be REST. If no port is specified, the connection should be peer. Probably, this is a Rails friendly way.

Or, Rails template might be good like Datamapper does, https://github.com/datamapper/dm-rails .

@avescodes
Copy link
Contributor Author

Hmm, do you oppose having a connection yaml? I honestly kind of like the config/database.yml style. I thought it might look like this:

For REST:

development:
  mode: rest
  uri: "localhost:9000"
  alias: development
  database: sample

For the peer:

development:
  mode: peer
  uri: "datomic:mem://sample"

Anyways, mongoid seems like a decent model that I've been building our Railtie off of.

At present I have the REST client connecting on startup. My TODO list entails:

  • fleshing out a lot of failure modes around startup
  • rewriting the connection API
  • more closely matching some oft-used ActiveModel APIs
  • adding generators for models

@yokolet
Copy link
Contributor

yokolet commented Nov 14, 2012

I'm not opposing your idea. Your idea is almost equivalent to Rails template. It is another idea I talked about.
With template, people would be able to create diametric specific database.yml for example:

rails new my_blog -m [diamtric template]

My first idea is easy to implement, and many gems use this initialization setting.

@avescodes
Copy link
Contributor Author

@yokolet Ahh OK. Yes, I will be borrowing heavily from other gems implementations of their own Railties.

@avescodes
Copy link
Contributor Author

My TODO list as of today:

  • config generator (rails g diametric:config) that installs config/diametric.yml)
  • Schema Initialization
    • Right now I'm thinking our own custom migration generator and DSL-extensions, though this deserves a lot more hammock time.
  • Raise actual error instances where possible (instead of strings)
  • 405 connections should raise errors (server up, but not allowed - happens when you connect to the wrong storage type)
  • Shorter timeouts for .create_database calls
  • (Needed?) Flesh out startup failure modes

Questions:

  • include Diametric::Persistence
    • How does this behave when no base connection is initialized

Niceties for later:

  • model generator
  • identity mapped entities
  • observers? (see mongoid)
  • reconnection? (see mongoid)

@yokolet
Copy link
Contributor

yokolet commented Nov 20, 2012

I'd paste how to use railties branch, which is from Ryan, so that I don't need to looking for my email box.
(edited so that rails won't try to connect to database and failed)

- rails new sample --skip-active-record
- Add "gem 'diametric', :path => '/path/to/repo'" to Gemfile
- bundle install
- Create config/diametric.yml with:

development:
  uri: "http://localhost:9000"
  storage: free
  database: sample

obviously, run bin/rest 9000 free …

@yokolet
Copy link
Contributor

yokolet commented Nov 20, 2012

I'll write about today's work. I could make Rails integration to go forward although rails app ended up in raising exception. My changes are in a new branch railtie.

Here's how to create Rails app using Diametric.

  1. create Rails app. Don't forget the "--skip-active-record" option.

    rails new sample --skip-active-record

  2. add Diametric gem in app's Gemfile

    gem 'diametric', :path => '/path/to/repo'

  3. bundle intall

  4. create config/diametric.yml

    # For REST connection
    development:
        uri: "http://localhost:9000"
        storage: free
        database: sample
    
    # For Peer connection
    development:
        uri: "datomic:mem://test"
  5. startup datomic if REST is used

    cd [datomic home]
    bin/rest 9000 free sample

  6. create 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
  7. create schema on datomic

    rake diametric:create_schema

  8. create controllers and views

    rails g scaffold post

  9. start rails

    rails s

  10. request http://localhost:3000/posts

It should work, but not :( The reason is Entity's all method doesn't work correctly.
The "all" method needs to be fixed.

@avescodes
Copy link
Contributor Author

Looking good! Just want to say you could probably do all your railtie work on the railsify branch–I don't see any harm in you continuing rails support on a single branch.

I see you added a diametric:create_schema task. I like that! I think it will let users create their schema for the time being, without committing to a big set of APIs that we'll need to keep/maintain.

I wanted to ask if you were planning to squeeze in a diametric:config raketask before closing this branch?

@avescodes
Copy link
Contributor Author

I will note though, you shouldn't need to include Diametric::Persistence::REST if you have set up a config/diaemtric.yml file, as that causes include DIametric::Persistence to automatically include the appropriate persistence type.

Step 5 could possibly be rewritten to use diametrics script/vendor-datomic-free. I'm not sure what the line to draw is on telling/showing people how to run Datomic.
Step 7 also has two "rake"s

@yokolet
Copy link
Contributor

yokolet commented Nov 21, 2012

Today, I added rake diametric:config, which generates diametric.yml.

Also, I confirmed most of basic Rails operations worked with Diametric. See https://github.com/relevance/diametric/wiki/Rails-Integration-(Experimental) , which explains how to create Rails app.

However, Diametric::Entity should have update and destroy methods to work with Rails. Currently, sample Rails app raises exception for that.

@avescodes
Copy link
Contributor Author

Hey, I merged railtie onto railsify.

On Wednesday, November 21, 2012 at 4:32 PM, Yoko Harada wrote:

Today, I added rake diametric:config, which generates diametric.yml.
Also, I confirmed most of basic Rails operations worked with Diametric. See https://github.com/relevance/diametric/wiki/Rails-Integration-(Experimental) , which explains how to create Rails app.
However, Diametric::Entity should have update and destroy methods to work with Rails. Currently, sample Rails app raises exception for that.


Reply to this email directly or view it on GitHub (#20 (comment)).

@yokolet
Copy link
Contributor

yokolet commented Nov 28, 2012

As in https://github.com/relevance/diametric/wiki/Rails-Integration-(Experimental), Rails scaffolding is now working for all index/ceate/show/edit/destroy methods.

Current TODO would be

  • exception handling when diametric raises exception
  • auto persistence module inclusion while rake tasks get run

@yokolet
Copy link
Contributor

yokolet commented Nov 28, 2012

Since Rails scaffolding is working, I merged railsify branch in to master and pushed it out.

@yokolet
Copy link
Contributor

yokolet commented Nov 29, 2012

I pushed the version 0.0.2 . Now, testing this feature got easy especially for peer connection, which has dependency to JAR archives.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants