• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Writing CouchDB Views using ClojureScript
 

Writing CouchDB Views using ClojureScript

on

  • 6,107 views

Write your views/filters/validators in Clojure(Script), run the results in CouchDB/Couchbase/Cloudant — no special view servers, no special configuration, no JavaScript!...

Write your views/filters/validators in Clojure(Script), run the results in CouchDB/Couchbase/Cloudant — no special view servers, no special configuration, no JavaScript!

More info: http://wp.me/p10OJi-bL

Statistics

Views

Total Views
6,107
Views on SlideShare
1,721
Embed Views
4,386

Actions

Likes
5
Downloads
25
Comments
0

11 Embeds 4,386

http://cemerick.com 4000
http://java.dzone.com 341
http://www.javaoracleblog.com 24
http://newsblur.com 5
http://www.newsblur.com 4
http://www.dzone.com 3
http://translate.googleusercontent.com 3
http://127.0.0.1 2
http://renren.it 2
http://www.online-home-jobs.com 1
http://www.renren.it 1
More...

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Writing CouchDB Views using ClojureScript Writing CouchDB Views using ClojureScript Presentation Transcript

    • Writing CouchDB Views using ClojureScript Chas Emerick @cemerick http://cemerick.com http://snowtide.comTuesday, October 11, 2011
    • @cemerick Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • @cemerick Founded Snowtide in 2001 Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • @cemerick Founded Snowtide in 2001 Clojure full-time since 2008 Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • @cemerick Founded Snowtide in 2001 Clojure full-time since 2008 Contributor to Clojure language & libraries Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • @cemerick Founded Snowtide in 2001 Clojure full-time since 2008 Contributor to Clojure language & libraries CouchDB user since 2009? Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • @cemerick Founded Snowtide in 2001 Clojure full-time since 2008 Contributor to Clojure language & libraries CouchDB user since 2009? O’Reilly author Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • CouchDB in 1 minute Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • CouchDB in 1 minute • Document-oriented data store Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • CouchDB in 1 minute • Document-oriented data store • (Primary) key => JSON object Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • CouchDB in 1 minute • Document-oriented data store • (Primary) key => JSON object • HTTP API Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • CouchDB in 1 minute • Document-oriented data store • (Primary) key => JSON object • HTTP API • Secondary indexes / queries provided by ‘views’ Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • CouchDB in 1 minute • Document-oriented data store • (Primary) key => JSON object • HTTP API • Secondary indexes / queries provided by ‘views’ • viz. materialized views in SQL-land Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • CouchDB in 1 minute • Document-oriented data store • (Primary) key => JSON object • HTTP API • Secondary indexes / queries provided by ‘views’ • viz. materialized views in SQL-land • Defined by Javascript functions applied within a flavour of map/reduce Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • CouchDB in 1 minute • Document-oriented data store • (Primary) key => JSON object • HTTP API • Secondary indexes / queries provided by ‘views’ • viz. materialized views in SQL-land • Defined by Javascript functions applied within a flavour of map/reduce • Same mechanism used elsewhere (filters, validation, etc) Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • Clutch Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • Clutch • CouchDB library for Clojure Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • Clutch • CouchDB library for Clojure • (Javascript) view creation and querying support: Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • Clutch • CouchDB library for Clojure • (Javascript) view creation and querying support: (save-­‐view  "count"  :number-­‐of-­‐players    {:map  "function(d){for  (var  k  in  d.players)  {emit(d.players[k],1);}}"      :reduce  "function  (keys,  values)  {  return  sum(values);  }"}) Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • “Javascript sucks” Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • “Javascript sucks” Q.E.D. Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • Clutch: Clojure view server Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • Clutch: Clojure view server • Use Clojure to write view functions: Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • Clutch: Clojure view server • Use Clojure to write view functions: (save-­‐view  "count"  :number-­‐of-­‐players    (with-­‐clj-­‐view-­‐server        {:map  (fn  [doc]  (map  #(vector  %  1)  (:players  doc)))          :reduce  (fn  [keys  values  _]  (reduce  +  values))})) Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • Clutch: Clojure view server • Use Clojure to write view functions: (save-­‐view  "count"  :number-­‐of-­‐players    (with-­‐clj-­‐view-­‐server        {:map  (fn  [doc]  (map  #(vector  %  1)  (:players  doc)))          :reduce  (fn  [keys  values  _]  (reduce  +  values))})) • Better, but: Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • Clutch: Clojure view server • Use Clojure to write view functions: (save-­‐view  "count"  :number-­‐of-­‐players    (with-­‐clj-­‐view-­‐server        {:map  (fn  [doc]  (map  #(vector  %  1)  (:players  doc)))          :reduce  (fn  [keys  values  _]  (reduce  +  values))})) • Better, but: • Increases operational complexity Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • Clutch: Clojure view server • Use Clojure to write view functions: (save-­‐view  "count"  :number-­‐of-­‐players    (with-­‐clj-­‐view-­‐server        {:map  (fn  [doc]  (map  #(vector  %  1)  (:players  doc)))          :reduce  (fn  [keys  values  _]  (reduce  +  values))})) • Better, but: • Increases operational complexity • Won’t work on hosted platforms, e.g. Cloudant Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • ClojureScript Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • ClojureScript • Clojure : JVM :: ClojureScript : JavaScript Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • ClojureScript • Clojure : JVM :: ClojureScript : JavaScript • Ahead-of-time compilation (no eval) Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • ClojureScript • Clojure : JVM :: ClojureScript : JavaScript • Ahead-of-time compilation (no eval) • (Optionally) uses Google Closure’s optimizing compiler Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • ClojureScript • Clojure : JVM :: ClojureScript : JavaScript • Ahead-of-time compilation (no eval) • (Optionally) uses Google Closure’s optimizing compiler • Eliminate need for Clojure/Clutch view server & need to write views in JavaScript! Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • Demo Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • Language Mapping Thankfully, you don’t need to do much if any interop in views… Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • Language Mapping Javascript Thankfully, you don’t need to do much if any interop in views… Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • Language Mapping Javascript emit([doc.a,  doc.b],  doc.c); Thankfully, you don’t need to do much if any interop in views… Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • Language Mapping Javascript emit([doc.a,  doc.b],  doc.c); ClojureScript Thankfully, you don’t need to do much if any interop in views… Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • Language Mapping Javascript emit([doc.a,  doc.b],  doc.c); ClojureScript (js/emit Thankfully, you don’t need to do much if any interop in views… Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • Language Mapping Javascript emit([doc.a,  doc.b],  doc.c); ClojureScript (js/emit    (array  (aget  doc  “a”) Thankfully, you don’t need to do much if any interop in views… Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • Language Mapping Javascript emit([doc.a,  doc.b],  doc.c); ClojureScript (js/emit    (array  (aget  doc  “a”)                  (aget  doc  “b”)) Thankfully, you don’t need to do much if any interop in views… Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • Language Mapping Javascript emit([doc.a,  doc.b],  doc.c); ClojureScript (js/emit    (array  (aget  doc  “a”)                  (aget  doc  “b”))    (aget  doc  “c”)) Thankfully, you don’t need to do much if any interop in views… Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • Current issues Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • Current issues • ClojureScript is not a library (yet!) Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • Current issues • ClojureScript is not a library (yet!) • Cannot be depended upon in Leiningen/ Maven Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • Current issues • ClojureScript is not a library (yet!) • Cannot be depended upon in Leiningen/ Maven • Cannot target / test against particular versions (there aren’t any) Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • Current issues • ClojureScript is not a library (yet!) • Cannot be depended upon in Leiningen/ Maven • Cannot target / test against particular versions (there aren’t any) • Incomplete optimization: lots of code generated to define the simplest view Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • Thank you! snipe book Chas Emerick @cemerick http://cemerick.com http://snowtide.com Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • Thank you! • CouchDB: http://couchdb.apache.org snipe book Chas Emerick @cemerick http://cemerick.com http://snowtide.com Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • Thank you! • CouchDB: http://couchdb.apache.org • Clutch: http://github.com/ashafa/clutch snipe book Chas Emerick @cemerick http://cemerick.com http://snowtide.com Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • Thank you! • CouchDB: http://couchdb.apache.org • Clutch: http://github.com/ashafa/clutch • ClojureScript: https://github.com/clojure/ clojurescript snipe book Chas Emerick @cemerick http://cemerick.com http://snowtide.com Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011
    • Thank you! • CouchDB: http://couchdb.apache.org • Clutch: http://github.com/ashafa/clutch • ClojureScript: https://github.com/clojure/ clojurescript • Clutch-ClojureScript: http://github.com/ cemerick/clutch-clojurescript snipe book Chas Emerick @cemerick http://cemerick.com http://snowtide.com Chas Emerick: Writing CouchDB Views using ClojureScriptTuesday, October 11, 2011