15. SQL vs. CouchDB * http ://www.zefhemel.com/archives/2008/03/11/sittin-on-the-couchdb Static queries of dynamic schemas Dynamic queries of static schemas Must know only document name Must know schema to read/write a complete object Denormalized. Docs usually self contained. Data often duplicated. Normalized. Objects spread across tables. Duplication reduced. Collection of named documents with varying structure Uniform tables of data Dynamic, implicit schema Predefined, explicit schema CouchDB SQL
16. Document = JSON Object { "_id":"discussion_tables", "_rev":"D1C946B7", "Subject":"I like Planktion", "Author":"Rusty", "PostedDate":"2006-08-15T17:30:12-04:00", "Tags":["plankton", "baseball", "decisions"], "Body":"I decided today that I don't like baseball. I like plankton." }
22. Extending ARes class CouchResource < ActiveResource::Base class << self def element_path(id, prefix_options = {}, query_options = nil) "#{prefix(prefix_options)}#{collection_name}/#{id}#{query_string(query_options)}" def collection_path(prefix_options = {}, query_options = nil) "#{prefix(prefix_options)}#{collection_name}#{query_string(query_options)}" def instantiate_collection(collection, prefix_options = {}) collection = collection.fetch("rows") if collection.kind_of? Hash def instantiate_record(record, prefix_options = {}) record = record.fetch("value") if record.has_key? "value“ def find_view(view_name, func_name) find(:all, :from => "/#{element_name}/_view/#{view_name}/#{func_name}") end
23. Mywiki Resource class Mywiki < CouchResource self.site = "http://localhost:5984" self.format = :json self.collection_name = 'mywiki' # used as a database name self.primary_key = '_id' end