Lasso and Couchdb : the happy couple

61
#LDC2014 / @stickbyatlas curl -X POST http://lasso.couchappy.com/ldc2014 -d '{"type":"attendee","name":"Ari","surname":"Najarian"}' -H 'Content-Type: application/json' While we're taking our break, do me a favour and type this into your Terminal: (swap your name & surname for mine)

description

Presentation on CouchDB delivered at the 2014 Lasso Developer Conference, at Lassosoft HQ in Newmarket, Ontario.

Transcript of Lasso and Couchdb : the happy couple

Page 1: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

curl -X POST http://lasso.couchappy.com/ldc2014

-d '{"type":"attendee","name":"Ari","surname":"Najarian"}'

-H 'Content-Type: application/json'

While we're taking our break, do me a favour and type this into your Terminal:(swap your name & surname for mine)

Page 2: Lasso and Couchdb : the happy couple
Page 3: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

Lasso & CouchDBThe happy couple.

PRESENTER: Ari Najarian • @stickbyatlas

Page 4: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

If I don’t include this slide, I’m probably going to forget to introduce myself.

INTRODUCTION

Page 5: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

If I don’t include this slide, I’m probably going to forget to introduce myself.

If you have a question or a comment, I’ll be monitoring Twitter!

INTRODUCTION

Page 6: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

I’ll be posting my slide deck online after the presentation. Look for a link to it on my Twitter stream.

INTRODUCTION

Page 7: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

What I hope to cover:CouchDB overviewDemo & orientationDesign documentsLasso usage patternsIntegrating CouchDBAdvanced Features

INTRODUCTION

Page 8: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

I’ve provided further reading for most of the topics I discuss. You can find these links on Delicious:delicious.com / stickbyatlas / LDC2014

INTRODUCTION

Page 9: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

A short history ofmy experience withrelational databases.

INTRODUCTION

Page 10: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

Microsoft AccessINTRODUCTION

Page 11: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

MySQL

INTRODUCTION

Page 12: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

PostgreSQL

INTRODUCTION

Page 13: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

Filemaker Server

INTRODUCTION

Page 14: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

SQLite

INTRODUCTION

Page 15: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

Relational databases suck at being easy to use.

Evidence: buggy tooling, obtuse configuration, and the fact that ORMs are an

actual thing people use in basically every web language.

INTRODUCTION

Page 16: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

Lasso’s Inline tag(and Ke’s Datasource)make interacting with

relational databases easy.( This is a huge selling point! )

INTRODUCTION

Page 17: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

But what if I told you there was an easier way

to persist data in your app?

Page 18: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

Introducing CouchDB

Let’s unpack this description a bit.

DOWNLOAD AT: couchdb.apache.org

Page 19: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

INTRODUCING COUCHDB

It's noSQLWhat's this mean?

Page 20: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

INTRODUCING COUCHDB

JSON for documents

Page 21: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

INTRODUCING COUCHDB

Javascript for Map / Reduce indexesThey're basically query expressions!

Page 22: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

INTRODUCING COUCHDB

HTTP for an API (!!)

Page 23: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

INTRODUCING COUCHDB

CouchDB can do master-master

replication

Page 24: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

INTRODUCING COUCHDB

It powers some prettyawesome products.

Page 25: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

INTRODUCING COUCHDB

It has enterprise backing.

Page 26: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

INTRODUCING COUCHDB

It's concurrent &highly available

CAP Theorem: A & P, not C

Page 27: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

INTRODUCING COUCHDB

It has an ecosystem!

PouchDB , Couchbase Lite

Page 28: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

A quick orientation

Demo time!

Page 29: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

Anatomy of adesign document

Page 30: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

{id : "_design/attendees"

}

ANATOMY OF A DESIGN DOC

Page 31: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

{id : "_design/attendees",views : {attendee_by_surname : function( doc ){ ... }

}}

ANATOMY OF A DESIGN DOC

Page 32: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

{id : "_design/attendees",shows : {view_attendee : function( doc , req ){ ... }edit_attendee : function( doc , req ){ ... }

},views : {attendee_by_surname : function( doc ){ ... }

}}

ANATOMY OF A DESIGN DOC

Page 33: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

{id : "_design/attendees",lists : {attendee_cards : function( head , req ){ ... }

},shows : {view_attendee : function( doc , req ){ ... }edit_attendee : function( doc , req ){ ... }

},views : {attendee_by_surname : function( doc ){ ... }

}}

ANATOMY OF A DESIGN DOC

Page 34: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

{id : "_design/attendees",updates : {toggle_CLD : function(doc, req){ ... }

}, lists : {attendee_cards : function( head , req ){ ... }

},shows : {view_attendee : function( doc , req ){ ... }edit_attendee : function( doc , req ){ ... }

},views : {attendees_by_surname : function( doc ){ ... }

}}

ANATOMY OF A DESIGN DOC

Page 35: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

{id : "_design/attendees",validate_doc_update : function( doc, prev , req ){ ... },updates : {toggle_CLD : function(doc, req){ ... }

}, lists : {attendee_cards : function( head , req ){ ... }

},shows : {view_attendee : function( doc , req ){ ... }edit_attendee : function( doc , req ){ ... }

},views : {attendees_by_surname : function( doc ){ ... }

}}

ANATOMY OF A DESIGN DOC

Page 36: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

Basic usage patterns

Page 37: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

Write a document to the database

BASIC USAGE PATTERNS

Page 38: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

Retrieve a document as a native Lasso map

BASIC USAGE PATTERNS

local("doc") = json_deserialize( include_url( "http://127.0.0.1:5984/database/DOC_ID" ));

Page 39: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

local("products") = json_deserialize( include_url( "http://127.0.0.1:5984/database/_design/ddoc/_view/products" ))->find("rows")->asstaticarray;

#products = with( p in products select #p->find( "value" ) );

Retrieve an array of maps from a view

BASIC USAGE PATTERNS

// VIEW: _design/ddoc/_view/productsfunction( doc ){ if( doc.type == "product" ) emit( doc.product_name , doc );}

Page 40: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

Update a document using an update handler.

/_design/attendees/_update/toggle_CLD

Page 41: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

Display pre-formatted data with a show function

/_design/attendees/_show

/DEMO_DOC{ "_id": "DEMO_DOC", "type": "attendee", "name": "Ari", "surname" : "Najarian"}

Page 42: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

Display pre-formatted data from a list function

/_design/attendees/_list/attendee_cards

/_design/attendees/_view/attendees_by_surname

Page 43: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

Cache & serve images via a Lasso proxy

BASIC USAGE PATTERNS

Page 44: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

<img src="/file/doc_id/attachment.jpg" />

Stream attachments from database

BASIC USAGE PATTERNS

RewriteRule ^/file/(.*) http://127.0.0.1:5984/database/$1 [P]

Page 45: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

How might you adoptCouchDB into yourdevelopment team?

Page 46: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

The integration continuum

MOSTLY LASSO

MOSTLYCOUCHDB

Page 47: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

THE INTEGRATION CONTINUUM

Authentication

Page 48: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

THE INTEGRATION CONTINUUM

Document Validation

Page 49: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

THE INTEGRATION CONTINUUM

Templating

Page 50: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

THE INTEGRATION CONTINUUM

File uploads

Page 51: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

THE INTEGRATION CONTINUUM

Real-time applications

Page 52: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

Advanced features& capabilities

Page 53: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

ADVANCED FEATURES

Geospatial queriesGeoCouch by Volker Mische ( @vmx )

Point & bounding-box coordinates

Page 54: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

ADVANCED FEATURES

Full-text searchCouchDB Lucene

Page 55: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

ADVANCED FEATURES

ClusteringBigCouch

Page 56: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

ADVANCED FEATURES

Offline-first development

Page 57: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

The big pictureEveryone else is trying to do this now.

Page 58: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

MongoDB-like querying syntaxBigCouch merge

Upcoming releases:

Page 59: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

CouchDB will challengeyour notions of what databases

can and should do.

Page 60: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

Further reading:

delicious.com / stickbyatlas / LDC2014

Page 61: Lasso and Couchdb : the happy couple

#LDC2014 / @stickbyatlas

Questions?