CouchDB Lightning Talk

803 views

Published on

The slides from my lightning talk on basic reporting using CouchDB. Given at SDRuby.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
803
On SlideShare
0
From Embeds
0
Number of Embeds
11
Actions
Shares
0
Downloads
8
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • CouchDB Lightning Talk

    1. 1. Basic Reporting with CouchDBHow to query with MapReduce rather than SQL
    2. 2. CouchRest• An ORM for CouchDB• CRUD works just like you think it would: create, get, save, destroy, etc• Schema-less. Objects extend from Hash.
    3. 3. The Event Objectclass Event < ::CouchRest::ExtendedDocumentuse_database::Database.depot_report_server.default_database # Accessors property :event property :email property :datetime, :cast_as => "Time" property :referer property :durationend
    4. 4. Create an Event!event = Event.new( :event => "purchase", :email => session.user.email, :datetime => Time.now, :referer => request.referer, :duration => Time.now - start_time )event[:price] = 30event.create
    5. 5. Find by emailclass Event < ::CouchRest::ExtendedDocument ... view_by :email, :map => "function(doc) { emit(doc[email], 1); }", :reduce => "_sum"endEvent.by_email(:key => "john@example.com")Event.by_email(:raw => true, :group => true, :reduce =>true)
    6. 6. Map
    7. 7. Reduce
    8. 8. Query a Date Rangeclass Event < ::CouchRest::ExtendedDocument ... view_by :event_and_date, :map => "function(doc) { if(doc[datetime] && doc[event]) { var date = new Date(doc[datetime]); var year = date.getFullYear(); var month = date.getMonth(); var day = date.getDate(); emit([doc[event], year, month, day], 1); } }", :reduce => "_sum"end
    9. 9. Reduce to get Totals
    10. 10. Adjust Granularity with group_level
    11. 11. Mash it up!

    ×