Lasso and Couchdb : the happy couple

Post on 29-Jun-2015

983 views 4 download

Tags:

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

#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)

#LDC2014 / @stickbyatlas

Lasso & CouchDBThe happy couple.

PRESENTER: Ari Najarian • @stickbyatlas

#LDC2014 / @stickbyatlas

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

INTRODUCTION

#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

#LDC2014 / @stickbyatlas

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

INTRODUCTION

#LDC2014 / @stickbyatlas

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

INTRODUCTION

#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

#LDC2014 / @stickbyatlas

A short history ofmy experience withrelational databases.

INTRODUCTION

#LDC2014 / @stickbyatlas

Microsoft AccessINTRODUCTION

#LDC2014 / @stickbyatlas

MySQL

INTRODUCTION

#LDC2014 / @stickbyatlas

PostgreSQL

INTRODUCTION

#LDC2014 / @stickbyatlas

Filemaker Server

INTRODUCTION

#LDC2014 / @stickbyatlas

SQLite

INTRODUCTION

#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

#LDC2014 / @stickbyatlas

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

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

INTRODUCTION

#LDC2014 / @stickbyatlas

But what if I told you there was an easier way

to persist data in your app?

#LDC2014 / @stickbyatlas

Introducing CouchDB

Let’s unpack this description a bit.

DOWNLOAD AT: couchdb.apache.org

#LDC2014 / @stickbyatlas

INTRODUCING COUCHDB

It's noSQLWhat's this mean?

#LDC2014 / @stickbyatlas

INTRODUCING COUCHDB

JSON for documents

#LDC2014 / @stickbyatlas

INTRODUCING COUCHDB

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

#LDC2014 / @stickbyatlas

INTRODUCING COUCHDB

HTTP for an API (!!)

#LDC2014 / @stickbyatlas

INTRODUCING COUCHDB

CouchDB can do master-master

replication

#LDC2014 / @stickbyatlas

INTRODUCING COUCHDB

It powers some prettyawesome products.

#LDC2014 / @stickbyatlas

INTRODUCING COUCHDB

It has enterprise backing.

#LDC2014 / @stickbyatlas

INTRODUCING COUCHDB

It's concurrent &highly available

CAP Theorem: A & P, not C

#LDC2014 / @stickbyatlas

INTRODUCING COUCHDB

It has an ecosystem!

PouchDB , Couchbase Lite

#LDC2014 / @stickbyatlas

A quick orientation

Demo time!

#LDC2014 / @stickbyatlas

Anatomy of adesign document

#LDC2014 / @stickbyatlas

{id : "_design/attendees"

}

ANATOMY OF A DESIGN DOC

#LDC2014 / @stickbyatlas

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

}}

ANATOMY OF A DESIGN DOC

#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

#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

#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

#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

#LDC2014 / @stickbyatlas

Basic usage patterns

#LDC2014 / @stickbyatlas

Write a document to the database

BASIC USAGE PATTERNS

#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" ));

#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 );}

#LDC2014 / @stickbyatlas

Update a document using an update handler.

/_design/attendees/_update/toggle_CLD

#LDC2014 / @stickbyatlas

Display pre-formatted data with a show function

/_design/attendees/_show

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

#LDC2014 / @stickbyatlas

Display pre-formatted data from a list function

/_design/attendees/_list/attendee_cards

/_design/attendees/_view/attendees_by_surname

#LDC2014 / @stickbyatlas

Cache & serve images via a Lasso proxy

BASIC USAGE PATTERNS

#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]

#LDC2014 / @stickbyatlas

How might you adoptCouchDB into yourdevelopment team?

#LDC2014 / @stickbyatlas

The integration continuum

MOSTLY LASSO

MOSTLYCOUCHDB

#LDC2014 / @stickbyatlas

THE INTEGRATION CONTINUUM

Authentication

#LDC2014 / @stickbyatlas

THE INTEGRATION CONTINUUM

Document Validation

#LDC2014 / @stickbyatlas

THE INTEGRATION CONTINUUM

Templating

#LDC2014 / @stickbyatlas

THE INTEGRATION CONTINUUM

File uploads

#LDC2014 / @stickbyatlas

THE INTEGRATION CONTINUUM

Real-time applications

#LDC2014 / @stickbyatlas

Advanced features& capabilities

#LDC2014 / @stickbyatlas

ADVANCED FEATURES

Geospatial queriesGeoCouch by Volker Mische ( @vmx )

Point & bounding-box coordinates

#LDC2014 / @stickbyatlas

ADVANCED FEATURES

Full-text searchCouchDB Lucene

#LDC2014 / @stickbyatlas

ADVANCED FEATURES

ClusteringBigCouch

#LDC2014 / @stickbyatlas

ADVANCED FEATURES

Offline-first development

#LDC2014 / @stickbyatlas

The big pictureEveryone else is trying to do this now.

#LDC2014 / @stickbyatlas

MongoDB-like querying syntaxBigCouch merge

Upcoming releases:

#LDC2014 / @stickbyatlas

CouchDB will challengeyour notions of what databases

can and should do.

#LDC2014 / @stickbyatlas

Further reading:

delicious.com / stickbyatlas / LDC2014

#LDC2014 / @stickbyatlas

Questions?