Intro to CouchDB

1,182 views

Published on

A quick introduction to CouchDB and CouchRest done at nwrug.org

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,182
On SlideShare
0
From Embeds
0
Number of Embeds
53
Actions
Shares
0
Downloads
23
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Intro to CouchDB

  1. 1. Intro to CouchDB<br />Ben Aldred<br />http://geekmade.co.uk<br />@benaldred<br />
  2. 2. Disclaimer<br /><ul><li>I am not a CouchDB expert
  3. 3. I still quite like Relational Databases</li></li></ul><li>Introducing...<br />
  4. 4. Apache<br />(so it must be good, right?)<br />
  5. 5. Document orientated Database<br />
  6. 6. CouchDB aims to solve problems<br />
  7. 7. Scaling<br />
  8. 8. Storing Data<br />
  9. 9. How?<br />
  10. 10. CouchDB Scales<br />just like rails!<br />
  11. 11. Non-locking Multiversion concurrency control (MVCC)<br />
  12. 12. Replication<br />
  13. 13. New way to model data<br />
  14. 14. Case Study: Invoices<br />
  15. 15. JSON<br />{ <br /> &quot;_id&quot;:&quot;hello-world&quot;,<br /> &quot;_rev&quot;:&quot;AE19EBC7654&quot;,<br /> &quot;title&quot;:&quot;Hello World&quot;,<br /> &quot;body&quot;:&quot;content...&quot;,<br /> &quot;date&quot;:&quot;2009/12/25 15:52:20&quot; <br />}<br />
  16. 16. JSON<br />{ <br />&quot;_id&quot;:&quot;hello-world&quot;,<br /> &quot;_rev&quot;:&quot;AE19EBC7654&quot;,<br /> &quot;title&quot;:&quot;Hello World&quot;,<br /> &quot;body&quot;:&quot;content...&quot;,<br /> &quot;date&quot;:&quot;2009/12/25 15:52:20&quot; <br />}<br />
  17. 17. JSON<br />{ <br /> &quot;_id&quot;:&quot;hello-world&quot;,<br />&quot;_rev&quot;:&quot;AE19EBC7654&quot;,<br /> &quot;title&quot;:&quot;Hello World&quot;,<br /> &quot;body&quot;:&quot;content...&quot;,<br /> &quot;date&quot;:&quot;2009/12/25 15:52:20&quot; <br />}<br />
  18. 18. HTTP REST API<br />Create: PUT /:db <br />Read: GET /:db/:docid<br />Update: PUT /:db/:docid<br />Delete: DELETE /:db/:docid<br />
  19. 19. Views<br />
  20. 20. Map<br />function(doc) {<br /> if(doc.date && doc.title) {<br /> emit(doc.date, doc.title); <br /> }<br />}<br /> key | value<br />-------------------------------------<br />&quot;2009/12/25 15:52:20&quot; | &quot;Hello World&quot;<br />
  21. 21. Query the View<br />http://localhost:5984/mydb/_design/post/_view/foo<br />
  22. 22. Query the View<br />http://localhost:5984/mydb/_design/post/_view/foo<br />
  23. 23. Demo<br />
  24. 24. When to use CouchDB<br />
  25. 25. When you need to scale<br />
  26. 26. When availibility is more important than consistency<br />
  27. 27. When not to use it<br />
  28. 28. You want to leaverage the power of an ORM<br />
  29. 29. CouchDB + Ruby<br />
  30. 30. CouchRest<br />
  31. 31. Core<br />couch = CouchRest.new(&quot;http://127.0.0.1:5984&quot;)<br />db = couch.database!(&apos;NWRUG&apos;)<br />db.save_doc({<br /> &apos;title&apos; =&gt; &apos;Intro to CouchDB&apos;,<br /> &apos;speaker&apos; =&gt; &apos;Ben Aldred&apos;,<br /> &apos;location&apos; =&gt; &apos;BBC&apos;,<br /> &apos;tags&apos; =&gt; [&apos;couchdb&apos;, &apos;ruby&apos;]<br />})<br />
  32. 32. More<br />class Presentation &lt; CouchRest::ExtendedDocument<br /> include ::CouchRest::Validation<br /> property :title<br /> property :speaker<br /> property :location<br /> validates_present :title<br />end<br />
  33. 33. More<br />Presentation.first<br />Presentation.all<br />Presentation.by_title(:key =&gt; &apos;Ben Aldred&apos;)<br />Presentation.get(&apos;intro_to_couchdb&apos;)<br />
  34. 34. More<br />property :questions, :cast_as =&gt; [&apos;Question&apos;]<br />property :speaker, :cast_as =&gt; &apos;Person&apos;<br />property :started_at, :cast_as =&gt; &apos;Time&apos;<br />
  35. 35. More<br />view_by :started_at, :descending =&gt; true<br />view_by :speaker, :title<br />
  36. 36. More<br />view_by :name,<br /> :map =&gt; <br /> &quot;function(doc) {<br /> if(doc.date && doc.title) {<br /> emit(doc.date, doc.title);<br /> }<br /> }&quot;<br />
  37. 37. Loads More<br />but I have not got time<br />
  38. 38. Resources<br /><ul><li>http://books.couchdb.org/relax/
  39. 39. http://github.com/jchris/couchrest
  40. 40. http://couch.io
  41. 41. http://labs.mudynamics.com/wp-content/uploads/2009/04/icouch.html
  42. 42. http://geekmade.co.uk</li>

×