Date post: | 18-May-2015 |
Category: |
Technology |
Upload: | benaldred |
View: | 1,038 times |
Download: | 2 times |
Intro to CouchDB
Ben Aldredhttp://geekmade.co.uk
@benaldred
Disclaimer• I am not a CouchDB expert• I still quite like Relational Databases
Introducing...
Apache(so it must be good, right?)
Document orientated Database
CouchDB aims to solve problems
Scaling
Storing Data
How?
CouchDB Scalesjust like rails!
Non-locking Multiversion
concurrency control (MVCC)
Replication
New way to model data
Case Study: Invoices
JSON{ "_id":"hello-world", "_rev":"AE19EBC7654", "title":"Hello World", "body":"content...", "date":"2009/12/25 15:52:20" }
JSON{ "_id":"hello-world", "_rev":"AE19EBC7654", "title":"Hello World", "body":"content...", "date":"2009/12/25 15:52:20" }
JSON{ "_id":"hello-world", "_rev":"AE19EBC7654", "title":"Hello World", "body":"content...", "date":"2009/12/25 15:52:20" }
HTTP REST APICreate: PUT /:db Read: GET /:db/:docidUpdate: PUT /:db/:docidDelete: DELETE /:db/:docid
Views
Mapfunction(doc) { if(doc.date && doc.title) { emit(doc.date, doc.title); }}
key | value-------------------------------------"2009/12/25 15:52:20" | "Hello World"
Query the Viewhttp://localhost:5984/mydb/_design/post/_view/foo
Query the Viewhttp://localhost:5984/mydb/_design/post/_view/foo
Demo
When to use CouchDB
When you need to scale
When availibility is more important than
consistency
When not to use it
You want to leaverage the power of an ORM
CouchDB + Ruby
CouchRest
Corecouch = CouchRest.new("http://127.0.0.1:5984")db = couch.database!('NWRUG')db.save_doc({ 'title' => 'Intro to CouchDB', 'speaker' => 'Ben Aldred', 'location' => 'BBC', 'tags' => ['couchdb', 'ruby']})
Moreclass Presentation < CouchRest::ExtendedDocument include ::CouchRest::Validation
property :title property :speaker property :location
validates_present :titleend
More
Presentation.firstPresentation.allPresentation.by_title(:key => 'Ben Aldred')Presentation.get('intro_to_couchdb')
More
property :questions, :cast_as => ['Question']property :speaker, :cast_as => 'Person'property :started_at, :cast_as => 'Time'
More
view_by :started_at, :descending => trueview_by :speaker, :title
Moreview_by :name, :map => "function(doc) { if(doc.date && doc.title) { emit(doc.date, doc.title); } }"
Loads More
but I have not got time
Resources•http://books.couchdb.org/relax/•http://github.com/jchris/couchrest•http://couch.io•http://labs.mudynamics.com/wp-content/uploads/2009/04/icouch.html •http://geekmade.co.uk