You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Paul Campbell <pa...@rushedsunlight.com> on 2009/02/09 03:21:04 UTC

Stuffing: a Ruby on Rails plugin to add CouchDB to existing ActiveRecord models

Hi all,

I've been very quiet around these parts, but I've noticed that there
are plenty of users on here that use Ruby/Rails. I've been working on
some CMS stuff backed with CouchDB and decided to do some abstracting
so that I could get my blog up and running off CouchDB. I thought you
might be interested in this:

http://www.pabcas.com/feeling/stuffing-couchdb-into-rails

Basically, it's a plugin that lets you use CouchDB with existing (or
new) ActiveRecord SQL models. You basically don't ever have to leave
ActiveRecord or SQL, but you get a bonus attribute (your 'stuffing')
that is a hash that persists to CouchDB.

In brief, it's something like this:

class Post < ActiveRecord::Base
  stuffing
end

@post = Post.new
@post.stuffing
=> {}
@post.stuffing_title = "Welcome to Stuffing"
@post.stuffing
=> {:title => "Welcome to Stuffing"}
@post.stuffing_title
=> "Welcome to Stuffing"

It's pretty basic stuff, but it's a really quick win if you want to
use CouchDB on top of existing ActiveRecord models, or if you want to
use the schema-less nature of CouchDB for your documents, but use
ActiveRecord finders, plugins and relationships.

The plugin itself is on Github where there's more examples and options etc.

http://github.com/paulca/stuffing/tree/master

Let me know if you think this is useful, or if you have any questions
about the motivations that led to writing this,

Paul

Re: Stuffing: a Ruby on Rails plugin to add CouchDB to existing ActiveRecord models

Posted by Andrea Schiavini <a....@sourcesense.com>.
Paul, does this handle the problem of conflicts in CouchDB - which may
result in an inconsistency between the MySQL database and its CouchDB
"mirror"?

Congratulations for your work ;)

Andrea Schiavini

2009/2/9 Paul Campbell <pa...@rushedsunlight.com>

> Chris,
>
> Totally. My hope is that anyone who's not had the time to fully
> investigate CouchDB will be able to just stick this in an ActiveRecord
> and have access to their CouchDB document as an accessor on an
> ActiveRecord model. Much less to get the head around than starting
> from scratch.
>
> The other neat thing about this is that it *just works* with
> ActiveRecord validations, at least with the first layer of hash keys.
> So the barrier to entry is pretty much install the plugin and call the
> method.
>
> Paul
>
> Paul Campbell
> paul@rushedsunlight.com
> - - - - - - - - - - - - - - - - - - -
> +353 87 914 8162
> Follow me on Twitter: http://www.twitter.com/paulca
>
>
>
> On Mon, Feb 9, 2009 at 2:47 AM, Chris Anderson <jc...@apache.org> wrote:
> > On Sun, Feb 8, 2009 at 6:21 PM, Paul Campbell <pa...@rushedsunlight.com>
> wrote:
> >> Hi all,
> >>
> >> I've been very quiet around these parts, but I've noticed that there
> >> are plenty of users on here that use Ruby/Rails. I've been working on
> >> some CMS stuff backed with CouchDB and decided to do some abstracting
> >> so that I could get my blog up and running off CouchDB. I thought you
> >> might be interested in this:
> >>
> >> http://www.pabcas.com/feeling/stuffing-couchdb-into-rails
> >>
> >> Basically, it's a plugin that lets you use CouchDB with existing (or
> >> new) ActiveRecord SQL models. You basically don't ever have to leave
> >> ActiveRecord or SQL, but you get a bonus attribute (your 'stuffing')
> >> that is a hash that persists to CouchDB.
> >>
> >
> > This is really cool. Back when we'd heard of Couch, but weren't yet
> > using it, we had a Rails plugin that serialized schemaless hashes to
> > JSON strings in Postgres. What you have sounds even better, what with
> > the actual Couch and all.
> >
> > Chris
> >
> > --
> > Chris Anderson
> > http://jchris.mfdz.com
> >
>

Re: Stuffing: a Ruby on Rails plugin to add CouchDB to existing ActiveRecord models

Posted by Paul Campbell <pa...@rushedsunlight.com>.
Chris,

Totally. My hope is that anyone who's not had the time to fully
investigate CouchDB will be able to just stick this in an ActiveRecord
and have access to their CouchDB document as an accessor on an
ActiveRecord model. Much less to get the head around than starting
from scratch.

The other neat thing about this is that it *just works* with
ActiveRecord validations, at least with the first layer of hash keys.
So the barrier to entry is pretty much install the plugin and call the
method.

Paul

Paul Campbell
paul@rushedsunlight.com
- - - - - - - - - - - - - - - - - - -
+353 87 914 8162
Follow me on Twitter: http://www.twitter.com/paulca



On Mon, Feb 9, 2009 at 2:47 AM, Chris Anderson <jc...@apache.org> wrote:
> On Sun, Feb 8, 2009 at 6:21 PM, Paul Campbell <pa...@rushedsunlight.com> wrote:
>> Hi all,
>>
>> I've been very quiet around these parts, but I've noticed that there
>> are plenty of users on here that use Ruby/Rails. I've been working on
>> some CMS stuff backed with CouchDB and decided to do some abstracting
>> so that I could get my blog up and running off CouchDB. I thought you
>> might be interested in this:
>>
>> http://www.pabcas.com/feeling/stuffing-couchdb-into-rails
>>
>> Basically, it's a plugin that lets you use CouchDB with existing (or
>> new) ActiveRecord SQL models. You basically don't ever have to leave
>> ActiveRecord or SQL, but you get a bonus attribute (your 'stuffing')
>> that is a hash that persists to CouchDB.
>>
>
> This is really cool. Back when we'd heard of Couch, but weren't yet
> using it, we had a Rails plugin that serialized schemaless hashes to
> JSON strings in Postgres. What you have sounds even better, what with
> the actual Couch and all.
>
> Chris
>
> --
> Chris Anderson
> http://jchris.mfdz.com
>

Re: Stuffing: a Ruby on Rails plugin to add CouchDB to existing ActiveRecord models

Posted by Chris Anderson <jc...@apache.org>.
On Sun, Feb 8, 2009 at 6:21 PM, Paul Campbell <pa...@rushedsunlight.com> wrote:
> Hi all,
>
> I've been very quiet around these parts, but I've noticed that there
> are plenty of users on here that use Ruby/Rails. I've been working on
> some CMS stuff backed with CouchDB and decided to do some abstracting
> so that I could get my blog up and running off CouchDB. I thought you
> might be interested in this:
>
> http://www.pabcas.com/feeling/stuffing-couchdb-into-rails
>
> Basically, it's a plugin that lets you use CouchDB with existing (or
> new) ActiveRecord SQL models. You basically don't ever have to leave
> ActiveRecord or SQL, but you get a bonus attribute (your 'stuffing')
> that is a hash that persists to CouchDB.
>

This is really cool. Back when we'd heard of Couch, but weren't yet
using it, we had a Rails plugin that serialized schemaless hashes to
JSON strings in Postgres. What you have sounds even better, what with
the actual Couch and all.

Chris

-- 
Chris Anderson
http://jchris.mfdz.com