couch_crumbs

DESCRIPTION:

A small library for basic CouchDB document-based apps.

FEATURES/PROBLEMS:

  • objects are JSON derived hashes

    (meaning properties support arrays, other hashes, dates, etc.)
    
  • named properties

  • timestamps (created_at/updated_at)

  • life-cycle callbacks

  • per-class database settings

  • simple “finder” views

  • advanced JavaScript views (in .json files)

  • document relationships

SYNOPSIS:

# Connect to a CouchDB server and set the default database
# :default_server is optional and defaults to http://couchdb.local/
# :default_database is also optional, and is used for classes
# that don't otherwise specify a database
CouchCrumbs::connect(:default_database => "example_database")

@server = CouchCrumbs.default_server

# Make sure we're running
@server.status

# Create or retrieve a database
@database = Database.new(:name => "example_database")

# Create a class
class Person

  # Mixin document goodness
  include CouchCrumbs::Document

  # Declare some properties
  property :name
  property :title
  property :status

  # Add :created_at and :updated_at properties
  timestamps!

  child_document :address

end

class Address

  include CouchCrumbs::Document

  property :location

  timestamps!

  parent_document :person

end

# Instantiate a new Person document with properties
@person = Person.new(:name => "Steve")
# Manually set a property
@person.title = "CEO"
# Save the document (with #before_save and #after_save callbacks)
@person.save!

# Get a single document from the database
@steve = Person.get!(@person.id)

# Instantiate and save a new document in a single call (w/ callbacks)
@bill = Person.create!(:name => "Bill", :status => "Retired")

# Destroy a document
@bill.destroy!

# Add an address to a person
@address = Address.create!(:location => "123 Main, Anytown USA")

@steve.address = @address

LIMITATIONS:

- lacks support for attachments
- lacks support for show functions
- lacks support for many other aspects of CouchDB
- both sides of an association must be saved before being set

REQUIREMENTS:

sudo gem install rest_client, json, english

INSTALL:

sudo gem install couch_crumbs

LICENSE:

(The MIT License)

Copyright © 2009 CouchCrumbs project.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ‘Software’), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.