development, ruby, conferences, frameworks, ruby on rails, confreaks, actsasconference 2009, Internet & Technology, Presentations & Spreadsheets

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    Favorites, Groups & Events

    development, ruby, conferences, frameworks, ruby on rails, confreaks, actsasconference 2009, Internet & Technology, Presentations & Spreadsheets - Presentation Transcript

    1. relaxing with couchdb will leinweber will@bitfission.com acts_as_conference 2009 1
    2. 2
    3. this talk: why & how 3
    4. what is couchdb? 4
    5. document database no schema 5
    6. erlang concurrent scalable 6
    7. built for the web restful json 7
    8. json { \"title\": \"A Brief History of Slinkies\", \"chapters\": [ { \"title\": \"Sorta like a spring\", \"text\": \"Round and metal...\" }, { \"title\": \"Stairs\", \"text\": \"They can go down, but not up\" }], \"_id\": \"4b859...\", \"_rev\": \"3280991488\" } 8
    9. multi version concurrency control no locking locking mvcc write reads 9
    10. add only never in a bad state 10
    11. incremental replication eventual consistency winning documents 11
    12. couchdb only apps javascript + html 12
    13. multiple databases for a single app 13
    14. integrate with full text search 14
    15. file attachment 15
    16. views (not queries) 16
    17. stored as design documents 17
    18. view server javascript (spidermonkey) ruby and python too 18
    19. map reduce (optional) 19
    20. goes through each document very slow 20
    21. map step emits keys value pairs 21
    22. persisted index keeps track of changes 22
    23. keep your views fresh 23
    24. http benefits 24
    25. cacheable load balancers 25
    26. easy interface understand and implement 26
    27. getting started 27
    28. install couch from svn head get erlang, spidermonkey, icu 28
    29. gem install jchris-couchrest lightweight api wrapper 29
    30. db = CouchRest.database!(\"http://localhost:5984/books\") response = db.save(:title => \"recipes\") # => {\"rev\"=>\"2351730874\", \"id\"=>\"07cb62...\", \"ok\"=>true} doc = db.get response[\"id\"] # => {\"title\"=>\"recipes\", \"_id\"=>\"07cb62...\", \"_rev\"=>\"2351730874\"} 30
    31. $ curl http://localhost:5984/books/07cb6232593b61dd022d1c05b1c7deac {\"_id\":\"07cb6232593b61dd022d1c05b1c7deac\",\"_rev\":\"2351730874\", \"title\":\"recipes\"} 31
    32. doc[\"title\"] = \"cook book\" doc.save # => true db.get response[\"id\"] # => {\"title\"=>\"cook book\", \"_id\"=>\"07cb623...\", \"_rev\"=>\"3767210759\"} doc.destroy # => true db.get response[\"id\"] # => RestClient::ResourceNotFound 32
    33. 33
    34. simple view function(doc) { if (doc.type == \"book\") { emit(null, doc); } db.view(\"books/all\") } 34
    35. view with keys function(doc) { emit(doc.type, doc); } db.view(\"books/all\" )['rows'].size # => 10 db.view(\"all/by_type\" )['rows'].size # => 30 db.view(\"all/by_type\", :key => \"book\")['rows'].size # => 10 35
    36. map reduce // map // reduce function(doc) { function(keys,values) { emit(doc.type, doc); return(values.length); } } db.view(\"count/by_type\") # => {\"rows\"=> {\"value\"=>3, \"key\"=>nil}]} db.view(\"count/by_type\", :group => true) # => {\"rows\"=>[{\"value\"=>10, \"key\"=>\"article\"}, {\"value\"=>10, \"key\"=>\"book\"}, {\"value\"=>10, \"key\"=>\"user\"}]} db.view(\"count/by_type\", :key => \"book\") # => {\"rows\"=>[{\"value\"=>10, \"key\"=>nil}]} 36
    37. versioning { \"title\": \"Slinkies!\", \"version\": 4, \"master_id\": \"3de0c...\", \"_id\": \"af322...\", \"chapters\": [...] } 37
    38. versioning // map // reduce function(doc) { function(keys, values) { emit( doc.master_id, var max = 0; doc ); } for(i in values) { if( values[i].version > values[max].version ) { max = i; } } return(values[max]); } 38
    39. view collation { \"_id\": \"def345\", { \"_id\": \"abc012\", \"_rev\": \"2387\", \"_rev\": \"2387\", \"type\": \"comment\", \"type\": \"post\", \"data\": \"...\" } \"data\": \"...\" } { \"_id\": \"r2d2c3\", \"_rev\": \"2653\", \"type\": \"comment\", \"data\": \"...\" } 39
    40. view collation function(doc) { if (doc.type == \"post\") { emit([doc._id, 0], doc); } else if (doc.type == \"comment\") { emit([doc.post, 1], doc); } } 40
    41. CouchRest::Model being removed from couchrest class Book < CouchRest::Model key_accessor :title, :text, :author cast :author, :as => \"User\" timestamps! end # config/environment.rb CouchRest::Model.default_database = CouchRest.database!(\"appname-#{ENV['RAILS_ENV']}\") 41
    42. others langalex-couch_potato active couch 42
    43. downsides 43
    44. moving target 44
    45. arbitrary queries are slow 45
    46. lack of supporting tools 46
    47. loss of intuition 47
    48. what you should do next 48
    49. thanks! 49

    + ActsAsConActsAsCon, 6 months ago

    custom

    974 views, 0 favs, 0 embeds more stats

    More info about this document

    © All Rights Reserved

    Go to text version

    • Total Views 974
      • 974 on SlideShare
      • 0 from embeds
    • Comments 0
    • Favorites 0
    • Downloads 25
    Most viewed embeds

    more

    All embeds

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories