Upholstering Apache CouchDB Who am I? Were hiring!! Apache - - PowerPoint PPT Presentation

upholstering apache couchdb who am i
SMART_READER_LITE
LIVE PREVIEW

Upholstering Apache CouchDB Who am I? Were hiring!! Apache - - PowerPoint PPT Presentation

Upholstering Apache CouchDB Who am I? Were hiring!! Apache CouchDB Document Storage Database Best at Replication Also Schemaless Uses Map/Reduce for indexing HTTP for querying JSON for everything else Can store


slide-1
SLIDE 1

Upholstering Apache CouchDB

slide-2
SLIDE 2

Who am I?

We’re hiring!!

slide-3
SLIDE 3

Apache CouchDB

  • Document Storage Database
  • Best at Replication
  • Also

– Schemaless – Uses Map/Reduce for indexing – HTTP for querying – JSON for everything else – Can store binaries as “attachments”

slide-4
SLIDE 4

Eventually Things Match

slide-5
SLIDE 5

WEB APPS ON COUCHDB

because you can…and they replicate!

slide-6
SLIDE 6

Apache CouchDB HTTP API

  • GET /{db}/

– Database info

  • GET /{db}/_all_docs

– List of all document’s info in the database – Primary Index

  • GET /{db}/{doc_id}

– JSON doc stored here

  • GET /{db}/{doc_id}/index.html

– Get the index.html file “attached” to the doc

slide-7
SLIDE 7

Apache CouchDB HTTP API

  • PUT /{db}/

– Create a database

  • PUT /{db}/{doc_id}

– Send in JSON to create a Document

  • PUT /{db}/{doc_id}/index.html

– Send in “anything” to create an attachment on that Document – `Content-Type: text/html`

slide-8
SLIDE 8

Web Apps on CouchDB

  • CouchDB is a web server
  • Good at Etags (304 Not Modified FTW!)
  • Virtual Host
  • (optionally) CORS enabled
  • Basic User Management
  • Simple Security Model
  • Flexible URL Space
slide-9
SLIDE 9

CouchApps / Design Docs

  • Extra Awesome
  • MapReduce indexing
  • Transform indexes
  • Transform documents
  • Handle special inbound formats

– XML, form encoding, CSV

  • Rewrite URLs
slide-10
SLIDE 10

GET /{db}/_design/{app}/

  • _view/{index}

– MapReduce index access

  • _list/{transform}/{index}

– Transform the index output

  • _show/{transform}/{doc_id}

– Transform a single document

  • _update/{parser}[/{doc_id}]

– Handle non-JSON (XML, form encoding, etc) updates

  • _rewrite/{path}

– Rewrite URLs

slide-11
SLIDE 11

In JSON

slide-12
SLIDE 12

On your file system

slide-13
SLIDE 13

_view/by_name?reduce=false

slide-14
SLIDE 14

_view/by_name

slide-15
SLIDE 15

_list/toHTML/by_name?reduce=false

slide-16
SLIDE 16

_show/toHTML/kwefsda

slide-17
SLIDE 17

POST _update/fromForm

slide-18
SLIDE 18

_rewrite/*

slide-19
SLIDE 19

Virtual Hosts

  • Configuration settings to map domains to _rewrite/

URLs

  • Magic
slide-20
SLIDE 20

TOOLS OF THE TRADE

Get on CouchDB

slide-21
SLIDE 21

Command Line for CouchDB

  • Couchapp.py (the granddaddy)
  • Erica
  • Node.couchapp.js
  • Gulp.js + couchdb-push
  • Kan.so
  • Casters
  • Reupholster
slide-22
SLIDE 22

couchapp.py

  • Or

– autopush – pushdocs – pushapps

slide-23
SLIDE 23

couchdb-push

  • JS-based & useable from node.js build scripts

(gulp, etc)

slide-24
SLIDE 24

couchdb-push in gulp.js

slide-25
SLIDE 25

UI for CouchDB

  • Futon (in CouchDB =< 1.6.1)
  • Fauxton (in CouchDB >= 2.0)
  • http://ddoc.me
  • Make one!
slide-26
SLIDE 26

BUNDLED.IN

Single Document Web App on CouchDB

slide-27
SLIDE 27

bundled.in on Phone & Desktop

slide-28
SLIDE 28

bundled.in

  • Video Game Bundle Buying Bonanza!
  • Single document drives UI

– Holds latest bundles + games list

  • Static HTML UI hosted from Cloudant

– Vue.js, superagent, Semantic-UI

  • No CouchApp stuff for this one (yet!)
  • Wishlist checker uses “external” Python host

– Filters main list by a screen scraped wishlist

slide-29
SLIDE 29

PILLOW NOTES

Markdown Editor on CouchDB

slide-30
SLIDE 30

Pillow Notes

  • Yet Another Markdown Editor Thing
  • JSON looks like:

– “_id”: “…title of the note…”, – “markdown”: “…the note…” – “created”: “…iso8601…” – “updated”: “…iso8601…”

slide-31
SLIDE 31

Pillow Notes

slide-32
SLIDE 32

Pillow Notes Implementation

  • HTML5, CSS, JS
  • PouchDB

– Persistence in browser – Replication out to CouchDB, Cloudant, etc

  • For backup, sharing, publication?
  • Vue.js

– Interaction

slide-33
SLIDE 33

Static Hosting Pillow Notes

  • On GitHub Pages

– http://bigbluehat.github.io/pillow-notes/

  • On Cloudant

– http://bigbluehat.cloudant.com/pillow- notes/_design/pillow-notes/_rewrite/

  • On CouchDB locally

slide-34
SLIDE 34

Pillow Notes & Replication

Username, Password, URL of Database Click “Sync” Bi-directional Replication MAY create conflicts

slide-35
SLIDE 35

CORS & Single Origin Pain

  • Cross Origin Resource Sharing

– Disables a core feature of the Web – Makes moving JSON with Browsers painful

  • (re?)Enable CORS

– – Cloudant has some UI, but only works over HTTPS

  • Can’t share without CORS being enabled
  • OK…it’s actually the Single Origin Policy…
slide-36
SLIDE 36

COUCHMAIL

Building a CouchApp

slide-37
SLIDE 37

CouchMail

  • Email archival on CouchDB
  • IMAP or Context.io
  • Cloudant Full-Text Search

– If hosted there

  • Binary attachment storage
  • Original message preservation

– Lawyers like this one.

slide-38
SLIDE 38

CouchMail Import

  • IMAP => JSON
  • Starts with newest
  • Can skip archived mail (or re-archive)
  • Stores “body parts” as attachments

– text/plain – text/html – …actual attachments based on media type

slide-39
SLIDE 39

DEVELOPING WITH DOCUMENTS

Thinking on CouchDB

slide-40
SLIDE 40

Development Process

  • Craft your JSON
  • Craft your Map/Reduce
  • …repeat…
  • Design some UI

– if you didn’t before you started

  • Implement that in HTML5, JS, and CSS
  • Use command line tools to publish into

CouchDB

slide-41
SLIDE 41

CouchMail the CouchApp

  • _design/couchapp

– _attachments/

  • index.html
  • css/*.css
  • Js/*.js

– views/

  • by_attachment_name
  • by_date

– Map.js – Reduce.js

  • shows

– atom.js

  • lists

– rss.js – atom.js

  • updates

– notes.js

  • validate_doc_update.js
  • rewrites.json
slide-42
SLIDE 42

The Filesystem Mapping

  • ddoc/

– _attachments/

  • index.html
  • bundle.js
  • styles.css

– _docs

  • fixture.json
  • settings.json

– Views

  • by_date

– map.js – reduce.js

  • shows

– xml.js

  • lists

– rss.js – atom.js

  • updates

– message.js

  • validate_doc_update.js
  • rewrites.json
slide-43
SLIDE 43

Thanks!

  • bigbluehat.com
  • @bigbluehat
  • github.com/BigBlueHat
  • bigbluehat on irc.freenode.net

– #couchdb #pouchdb #hypothes.is

  • bigbluehat@apache.org
  • byoung@bigbluehat.com
  • bigbluehat@hypothes.is