Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

CouchDB @ red dirt ruby conference

1,736 views

Published on

My presentation of CouchDB at red dirt ruby conference May 6th 2010

Published in: Technology
  • Be the first to comment

CouchDB @ red dirt ruby conference

  1. 1. couchdb, ruby, and you. will leinweber — bitfission.com — merge.fm — @leinweber
  2. 2. will leinweber will leinweber — bitfission.com — merge.fm — @leinweber
  3. 3. couchdb will leinweber — bitfission.com — merge.fm — @leinweber
  4. 4. will leinweber — bitfission.com — merge.fm — @leinweber
  5. 5. will leinweber — bitfission.com — merge.fm — @leinweber
  6. 6. documents will leinweber — bitfission.com — merge.fm — @leinweber
  7. 7. json will leinweber — bitfission.com — merge.fm — @leinweber
  8. 8. rich documents will leinweber — bitfission.com — merge.fm — @leinweber
  9. 9. { "_id": "will", "_rev": "3-4352629382", "fullname": "Will Leinweber", "email": "will@bitfission.com", "sites": [ {"blog": "bitfission.com", "hits": 42}, {"github": "github.com/will"}, {"twitter": "twitter.com/leinweber"}, {"company": "merge.fm"} ] } will leinweber — bitfission.com — merge.fm — @leinweber
  10. 10. schemaless will leinweber — bitfission.com — merge.fm — @leinweber
  11. 11. http api will leinweber — bitfission.com — merge.fm — @leinweber
  12. 12. restful will leinweber — bitfission.com — merge.fm — @leinweber
  13. 13. ~% curl localhost:5984/appdb/docid {"_id":"docid","_rev":"2-3779119708","look":"at all this data","its_awesome":true} will leinweber — bitfission.com — merge.fm — @leinweber
  14. 14. ~% curl localhost:5984/appdb/docid -i HTTP/1.1 200 OK Server: CouchDB/0.11.0 (Erlang OTP/R13B) Etag: "2-3779119708" Date: Wed, 28 Apr 2010 06:46:42 GMT Content-Type: text/plain;charset=utf-8 Content-Length: 83 Cache-Control: must-revalidate will leinweber — bitfission.com — merge.fm — @leinweber
  15. 15. caching will leinweber — bitfission.com — merge.fm — @leinweber
  16. 16. clustering will leinweber — bitfission.com — merge.fm — @leinweber
  17. 17. replication will leinweber — bitfission.com — merge.fm — @leinweber
  18. 18. couchapps! will leinweber — bitfission.com — merge.fm — @leinweber
  19. 19. views will leinweber — bitfission.com — merge.fm — @leinweber
  20. 20. javascript map/reduce will leinweber — bitfission.com — merge.fm — @leinweber
  21. 21. map will leinweber — bitfission.com — merge.fm — @leinweber
  22. 22. bit.ly/jscouchdb example will leinweber — bitfission.com — merge.fm — @leinweber
  23. 23. {"_id":1,"name":"fish.jpg","user":"bob","camera":"nikon", "info":{"width":100,"height":200,"size":12345},"tags":["tuna","shark"]} {"_id":2,"name":"trees.jpg","user":"john","camera":"canon", "info":{"width":30,"height":250,"size":32091},"tags":["oak"]} {"_id":3,"name":"snow.png","user":"john","camera":"canon", "info":{"width":64,"height":64,"size":1253},"tags":["tahoe","powder"]} {"_id":4,"name":"hawaii.png","user":"john","camera":"nikon", "info":{"width":128,"height":64,"size":92834},"tags":["maui","tuna"]} {"_id":5,"name":"hawaii.gif","user":"bob","camera":"canon", "info":{"width":320,"height":128,"size":49287},"tags":["maui"]} {"_id":6,"name":"island.gif","user":"zztop","camera":"nikon", "info":{"width":640,"height":480,"size":50398},"tags":["maui"]} will leinweber — bitfission.com — merge.fm — @leinweber
  24. 24. function(doc) { emit(doc.user, null); } { "total_rows": 6, "rows": [ {"id":"1","key":"bob","value":null}, {"id":"5","key":"bob","value":null}, {"id":"2","key":"john","value":null}, {"id":"3","key":"john","value":null}, {"id":"4","key":"john","value":null}, {"id":"6","key":"zztop","value":null} ] } will leinweber — bitfission.com — merge.fm — @leinweber
  25. 25. function(doc) { emit(doc.name.match(/w+.(w{3})/)[1], null); } { "total_rows": 6, "rows": [ {"id":"5","key":"gif","value":null}, {"id":"6","key":"gif","value":null}, {"id":"1","key":"jpg","value":null}, {"id":"2","key":"jpg","value":null}, {"id":"3","key":"png","value":null}, {"id":"4","key":"png","value":null} ] } will leinweber — bitfission.com — merge.fm — @leinweber
  26. 26. function(doc) { emit(doc.name.match(/w+.(w{3})/)[1], null); } ?key="jpg" { "total_rows": 2, "rows": [ {"id":"1","key":"jpg","value":null}, {"id":"2","key":"jpg","value":null}, ] } will leinweber — bitfission.com — merge.fm — @leinweber
  27. 27. //reduce //map function(doc) { function(keys,values,rereduce) { emit("size",doc.info.size); return sum(values); } } id key value 1 "size" 12345 { 2 "size" 32091     "rows": [ reduced 3 "size" 1253         {"key":"size","value":238208} 238208 4 "size" 92834      ] 5 "size" 49287 } 6 "size" 50398 will leinweber — bitfission.com — merge.fm — @leinweber
  28. 28. //reduce //map function(doc) { function(keys,values,rereduce) { emit(doc.user, 1); return sum(values); } } id key value reduced { 1 "bob" 1     "rows": [ 2 "bob" 1 2         {"key":"bob","value":2}, 3 "john" 1         {"key":"john","value":3}, 4 "john" 1 3         {"key":"zztop","value":1} 5 "john" 1      ] 6 "zztop" 1 1 } will leinweber — bitfission.com — merge.fm — @leinweber
  29. 29. last example: complex keys will leinweber — bitfission.com — merge.fm — @leinweber
  30. 30. {"_id":1,"name":"fish.jpg","user":"bob","camera":"nikon", "info":{"width":100,"height":200,"size":12345},"tags":["tuna","shark"]} {"_id":2,"name":"trees.jpg","user":"john","camera":"canon", "info":{"width":30,"height":250,"size":32091},"tags":["oak"]} {"_id":3,"name":"snow.png","user":"john","camera":"canon", "info":{"width":64,"height":64,"size":1253},"tags":["tahoe","powder"]} {"_id":4,"name":"hawaii.png","user":"john","camera":"nikon", "info":{"width":128,"height":64,"size":92834},"tags":["maui","tuna"]} {"_id":5,"name":"hawaii.gif","user":"bob","camera":"canon", "info":{"width":320,"height":128,"size":49287},"tags":["maui"]} {"_id":6,"name":"island.gif","user":"zztop","camera":"nikon", "info":{"width":640,"height":480,"size":50398},"tags":["maui"]} will leinweber — bitfission.com — merge.fm — @leinweber
  31. 31. //map //reduce function(doc) { function(keys,values,rereduce){ emit([doc.user,doc.camera],1); return sum(values); } } id key value reduced { "rows": [ 5 ["bob","canon"] 1 1    {"key":["bob","canon"],"value":1}, 1 ["bob","nikon"] 1 1     {"key":["bob","nikon"],"value":1}, 2 ["john","canon"] 1     {"key":["john","canon"],"value":2}, 2 3 ["john","canon"] 1     {"key":["john","nikon"],"value":1}, 4 ["john","nikon"] 1 1     {"key":["zztop","nikon"],"value":1}    ] 6 ["zztop","nikon"] 1 1 } will leinweber — bitfission.com — merge.fm — @leinweber
  32. 32. //map //reduce function(doc) { function(keys,values,rereduce){ emit([doc.user,doc.camera],1); return sum(values); } } ?startkey=[“bob”]&endkey=[“bob”,{}] { "rows": [    {"key":["bob","canon"],"value":1},     {"key":["bob","nikon"],"value":1},    ] } will leinweber — bitfission.com — merge.fm — @leinweber
  33. 33. views are saved b+ trees will leinweber — bitfission.com — merge.fm — @leinweber
  34. 34. updated when accessed will leinweber — bitfission.com — merge.fm — @leinweber
  35. 35. updated incrementally will leinweber — bitfission.com — merge.fm — @leinweber
  36. 36. couchrest will leinweber — bitfission.com — merge.fm — @leinweber
  37. 37. will leinweber — bitfission.com — merge.fm — @leinweber
  38. 38. couchrest core will leinweber — bitfission.com — merge.fm — @leinweber
  39. 39. DB = CouchRest.database!("temps") DB.save_doc "_id" => "room1", "temps" => [34] #=> {"rev"=>"1-3b4f6c5218621d8876", "id"=>"room1", "ok"=>true} room = DB.get "room1" #=> {"temps"=>[34], "_rev"=>"1-3b4f6c5218621", "_id"=>"room1"} room["temps"] << 35 << 25 << 33 << 25 room.save #=> {"temps"=>[34,35,25,33,25],"_rev"=>"2-1d15c4a8a","_id"=>"room1"} will leinweber — bitfission.com — merge.fm — @leinweber
  40. 40. DB.view("temps/temp", :key=>25) #=> {"total_rows"=>5, "rows"=>[ {"id"=>"room1", "value"=>{...}, "key"=>25} ]} will leinweber — bitfission.com — merge.fm — @leinweber
  41. 41. Extended Document will leinweber — bitfission.com — merge.fm — @leinweber
  42. 42. class User < CouchRest::ExtendedDocument property :name property :email property :posts, :default => [], :accessible => true timestamps! view_by :name view_by :post_ids, :map => %Q("function(doc) { if (doc['couchrest-type']=='User' && doc.post_ids){...) validates_with_method :name, :valid_name? validates_presence_of :email before_save :update_posts end will leinweber — bitfission.com — merge.fm — @leinweber
  43. 43. get couchdb will leinweber — bitfission.com — merge.fm — @leinweber
  44. 44. homebrew couchdbx build will leinweber — bitfission.com — merge.fm — @leinweber
  45. 45. links will leinweber — bitfission.com — merge.fm — @leinweber
  46. 46. couchdb.apache.org books.couchdb.org github.com/couchrest bit.ly/jscouchdb will leinweber — bitfission.com — merge.fm — @leinweber
  47. 47. thanks will leinweber — bitfission.com — merge.fm — @leinweber
  48. 48. will leinweber — bitfission.com — merge.fm — @leinweber

×