Top Banner
CouchDB application development Developing and deploying CouchApps Jakob Westhoff <[email protected]> PHPBarcamp.at May 1, 2010 http://westhoffswelt.de jakob@westhoffswelt.de slide: 1 / 35
147
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Developing CouchApps

CouchDB application developmentDeveloping and deploying CouchApps

Jakob Westhoff <[email protected]>

PHPBarcamp.atMay 1, 2010

http://westhoffswelt.de [email protected] slide: 1 / 35

Page 2: Developing CouchApps

About Me

Jakob Westhoff

PHP developer for more several years

Computer science student at the TU Dortmund

Co-Founder of the PHP Usergroup Dortmund

Active in different Open Source projects

http://westhoffswelt.de [email protected] slide: 2 / 35

Page 3: Developing CouchApps

Asking the audience

Who is actively using CouchDB?

Who played with CouchDB just for fun?

Who has heard of CouchDB, but never used it?

Who has already developed a CouchApp?

Who does not know at all, what a CouchApp is?

http://westhoffswelt.de [email protected] slide: 3 / 35

Page 4: Developing CouchApps

Asking the audience

Who is actively using CouchDB?

Who played with CouchDB just for fun?

Who has heard of CouchDB, but never used it?

Who has already developed a CouchApp?

Who does not know at all, what a CouchApp is?

http://westhoffswelt.de [email protected] slide: 3 / 35

Page 5: Developing CouchApps

Asking the audience

Who is actively using CouchDB?

Who played with CouchDB just for fun?

Who has heard of CouchDB, but never used it?

Who has already developed a CouchApp?

Who does not know at all, what a CouchApp is?

http://westhoffswelt.de [email protected] slide: 3 / 35

Page 6: Developing CouchApps

Asking the audience

Who is actively using CouchDB?

Who played with CouchDB just for fun?

Who has heard of CouchDB, but never used it?

Who has already developed a CouchApp?

Who does not know at all, what a CouchApp is?

http://westhoffswelt.de [email protected] slide: 3 / 35

Page 7: Developing CouchApps

Asking the audience

Who is actively using CouchDB?

Who played with CouchDB just for fun?

Who has heard of CouchDB, but never used it?

Who has already developed a CouchApp?

Who does not know at all, what a CouchApp is?

http://westhoffswelt.de [email protected] slide: 3 / 35

Page 8: Developing CouchApps

Goals of this session

Understand what a CouchApp actually is

Learn what features of CouchDB can be used to realize aCouchApp

Get a glimpse of third party tools and frameworks forCouchApp development

http://westhoffswelt.de [email protected] slide: 4 / 35

Page 9: Developing CouchApps

Goals of this session

Understand what a CouchApp actually is

Learn what features of CouchDB can be used to realize aCouchApp

Get a glimpse of third party tools and frameworks forCouchApp development

http://westhoffswelt.de [email protected] slide: 4 / 35

Page 10: Developing CouchApps

Goals of this session

Understand what a CouchApp actually is

Learn what features of CouchDB can be used to realize aCouchApp

Get a glimpse of third party tools and frameworks forCouchApp development

http://westhoffswelt.de [email protected] slide: 4 / 35

Page 11: Developing CouchApps

What is CouchDB?

Document based NoSQL database

Written in Erlang

MapReduce based indexing

Javascript uses as embedded language

RESTful JSON API

Build in incremental bi-directional replication

http://westhoffswelt.de [email protected] slide: 5 / 35

Page 12: Developing CouchApps

What is CouchDB?

Document based NoSQL database

Written in Erlang

MapReduce based indexing

Javascript uses as embedded language

RESTful JSON API

Build in incremental bi-directional replication

http://westhoffswelt.de [email protected] slide: 5 / 35

Page 13: Developing CouchApps

What is CouchDB?

Document based NoSQL database

Written in Erlang

MapReduce based indexing

Javascript uses as embedded language

RESTful JSON API

Build in incremental bi-directional replication

http://westhoffswelt.de [email protected] slide: 5 / 35

Page 14: Developing CouchApps

What is CouchDB?

Document based NoSQL database

Written in Erlang

MapReduce based indexing

Javascript uses as embedded language

RESTful JSON API

Build in incremental bi-directional replication

http://westhoffswelt.de [email protected] slide: 5 / 35

Page 15: Developing CouchApps

What is CouchDB?

Document based NoSQL database

Written in Erlang

MapReduce based indexing

Javascript uses as embedded language

RESTful JSON API

Build in incremental bi-directional replication

http://westhoffswelt.de [email protected] slide: 5 / 35

Page 16: Developing CouchApps

What is CouchDB?

Document based NoSQL database

Written in Erlang

MapReduce based indexing

Javascript uses as embedded language

RESTful JSON API

Build in incremental bi-directional replication

http://westhoffswelt.de [email protected] slide: 5 / 35

Page 17: Developing CouchApps

CouchDB document example

Documents are stored as JSON

{” i d ” : ” r e c i p e−some−r e c i p e ” ,” r e v ” : ”1−859 e8f9a06b864ebca3a929750c17537 ” ,” date ” : 1270067388 ,” t i t l e ” : ”Some r e c i p e ” ,” i n g r e d i e n t s ” : [

” Sugar ” ,” F l ou r ”] ,” i n s t r u c t i o n s ” : ”Some i n s t r u c t i o n s ” ,” u s e r ” : ” use r−f o oba r ” ,

}

http://westhoffswelt.de [email protected] slide: 6 / 35

Page 18: Developing CouchApps

CouchDB document example

Documents are stored as JSON

{” i d ” : ” r e c i p e−some−r e c i p e ” ,” r e v ” : ”1−859 e8f9a06b864ebca3a929750c17537 ” ,” date ” : 1270067388 ,” t i t l e ” : ”Some r e c i p e ” ,” i n g r e d i e n t s ” : [

” Sugar ” ,” F l ou r ”] ,” i n s t r u c t i o n s ” : ”Some i n s t r u c t i o n s ” ,” u s e r ” : ” use r−f o oba r ” ,

}

http://westhoffswelt.de [email protected] slide: 6 / 35

Page 19: Developing CouchApps

What is a CouchApp?

Application build on top of CouchDB which fits the followingcriteria:

Using CouchDB as data storeStored inside the CouchDBServed using the CouchDB Http-Server

Most CouchApps are

Mostly written in JavascriptUsing some sort of Javascript library

CouchDB replication can be used to deploy applications

http://westhoffswelt.de [email protected] slide: 7 / 35

Page 20: Developing CouchApps

What is a CouchApp?

Application build on top of CouchDB which fits the followingcriteria:

Using CouchDB as data storeStored inside the CouchDBServed using the CouchDB Http-Server

Most CouchApps are

Mostly written in JavascriptUsing some sort of Javascript library

CouchDB replication can be used to deploy applications

http://westhoffswelt.de [email protected] slide: 7 / 35

Page 21: Developing CouchApps

What is a CouchApp?

Application build on top of CouchDB which fits the followingcriteria:

Using CouchDB as data storeStored inside the CouchDBServed using the CouchDB Http-Server

Most CouchApps are

Mostly written in JavascriptUsing some sort of Javascript library

CouchDB replication can be used to deploy applications

http://westhoffswelt.de [email protected] slide: 7 / 35

Page 22: Developing CouchApps

What is a CouchApp?

Application build on top of CouchDB which fits the followingcriteria:

Using CouchDB as data storeStored inside the CouchDBServed using the CouchDB Http-Server

Most CouchApps are

Mostly written in JavascriptUsing some sort of Javascript library

CouchDB replication can be used to deploy applications

http://westhoffswelt.de [email protected] slide: 7 / 35

Page 23: Developing CouchApps

What is a CouchApp?

Application build on top of CouchDB which fits the followingcriteria:

Using CouchDB as data storeStored inside the CouchDBServed using the CouchDB Http-Server

Most CouchApps are

Mostly written in JavascriptUsing some sort of Javascript library

CouchDB replication can be used to deploy applications

http://westhoffswelt.de [email protected] slide: 7 / 35

Page 24: Developing CouchApps

What is a CouchApp?

Application build on top of CouchDB which fits the followingcriteria:

Using CouchDB as data storeStored inside the CouchDBServed using the CouchDB Http-Server

Most CouchApps are

Mostly written in JavascriptUsing some sort of Javascript library

CouchDB replication can be used to deploy applications

http://westhoffswelt.de [email protected] slide: 7 / 35

Page 25: Developing CouchApps

What is a CouchApp?

Application build on top of CouchDB which fits the followingcriteria:

Using CouchDB as data storeStored inside the CouchDBServed using the CouchDB Http-Server

Most CouchApps are

Mostly written in JavascriptUsing some sort of Javascript library

CouchDB replication can be used to deploy applications

http://westhoffswelt.de [email protected] slide: 7 / 35

Page 26: Developing CouchApps

What is a CouchApp?

Application build on top of CouchDB which fits the followingcriteria:

Using CouchDB as data storeStored inside the CouchDBServed using the CouchDB Http-Server

Most CouchApps are

Mostly written in JavascriptUsing some sort of Javascript library

CouchDB replication can be used to deploy applications

http://westhoffswelt.de [email protected] slide: 7 / 35

Page 27: Developing CouchApps

What is a CouchApp?

Application build on top of CouchDB which fits the followingcriteria:

Using CouchDB as data storeStored inside the CouchDBServed using the CouchDB Http-Server

Most CouchApps are

Mostly written in JavascriptUsing some sort of Javascript library

CouchDB replication can be used to deploy applications

http://westhoffswelt.de [email protected] slide: 7 / 35

Page 28: Developing CouchApps

Excursion: Futon

Futon is CouchDBs adminstration interfaceAutomatically available on every CouchDB

http://localhost:5984/ utils/

http://westhoffswelt.de [email protected] slide: 8 / 35

Page 29: Developing CouchApps

Excursion: Futon

Futon is CouchDBs adminstration interfaceAutomatically available on every CouchDB

http://localhost:5984/ utils/

http://westhoffswelt.de [email protected] slide: 8 / 35

Page 30: Developing CouchApps

Excursion: Futon

Futon is CouchDBs adminstration interfaceAutomatically available on every CouchDB

http://localhost:5984/ utils/

http://westhoffswelt.de [email protected] slide: 8 / 35

Page 31: Developing CouchApps

Which CouchDB Version to use?

CouchDB 0.11 or greater

User managementAuthentication API: Cookie, OAuth, plain-HTTPPer-db reader access listsValidation functionsUrl rewritingVhost configuration

http://westhoffswelt.de [email protected] slide: 9 / 35

Page 32: Developing CouchApps

Which CouchDB Version to use?

CouchDB 0.11 or greater

User managementAuthentication API: Cookie, OAuth, plain-HTTPPer-db reader access listsValidation functionsUrl rewritingVhost configuration

http://westhoffswelt.de [email protected] slide: 9 / 35

Page 33: Developing CouchApps

Which CouchDB Version to use?

CouchDB 0.11 or greater

User managementAuthentication API: Cookie, OAuth, plain-HTTPPer-db reader access listsValidation functionsUrl rewritingVhost configuration

http://westhoffswelt.de [email protected] slide: 9 / 35

Page 34: Developing CouchApps

Which CouchDB Version to use?

CouchDB 0.11 or greater

User managementAuthentication API: Cookie, OAuth, plain-HTTPPer-db reader access listsValidation functionsUrl rewritingVhost configuration

http://westhoffswelt.de [email protected] slide: 9 / 35

Page 35: Developing CouchApps

Which CouchDB Version to use?

CouchDB 0.11 or greater

User managementAuthentication API: Cookie, OAuth, plain-HTTPPer-db reader access listsValidation functionsUrl rewritingVhost configuration

http://westhoffswelt.de [email protected] slide: 9 / 35

Page 36: Developing CouchApps

Which CouchDB Version to use?

CouchDB 0.11 or greater

User managementAuthentication API: Cookie, OAuth, plain-HTTPPer-db reader access listsValidation functionsUrl rewritingVhost configuration

http://westhoffswelt.de [email protected] slide: 9 / 35

Page 37: Developing CouchApps

Which CouchDB Version to use?

CouchDB 0.11 or greater

User managementAuthentication API: Cookie, OAuth, plain-HTTPPer-db reader access listsValidation functionsUrl rewritingVhost configuration

http://westhoffswelt.de [email protected] slide: 9 / 35

Page 38: Developing CouchApps

CouchApp techniques

Store all application files as document attachments

Attachments can be stored for any document inside CouchDBCan be directly accesed using the RESTful interface

Use CouchDBs authentication backend for user management

Use validation function for access restrictions

Use show and list functions to output HTML

Access CouchDB using Javascript and XHR

Use CouchDB vhosts and url rewriting for nice urls

http://westhoffswelt.de [email protected] slide: 10 / 35

Page 39: Developing CouchApps

CouchApp techniques

Store all application files as document attachments

Attachments can be stored for any document inside CouchDBCan be directly accesed using the RESTful interface

Use CouchDBs authentication backend for user management

Use validation function for access restrictions

Use show and list functions to output HTML

Access CouchDB using Javascript and XHR

Use CouchDB vhosts and url rewriting for nice urls

http://westhoffswelt.de [email protected] slide: 10 / 35

Page 40: Developing CouchApps

CouchApp techniques

Store all application files as document attachments

Attachments can be stored for any document inside CouchDBCan be directly accesed using the RESTful interface

Use CouchDBs authentication backend for user management

Use validation function for access restrictions

Use show and list functions to output HTML

Access CouchDB using Javascript and XHR

Use CouchDB vhosts and url rewriting for nice urls

http://westhoffswelt.de [email protected] slide: 10 / 35

Page 41: Developing CouchApps

CouchApp techniques

Store all application files as document attachments

Attachments can be stored for any document inside CouchDBCan be directly accesed using the RESTful interface

Use CouchDBs authentication backend for user management

Use validation function for access restrictions

Use show and list functions to output HTML

Access CouchDB using Javascript and XHR

Use CouchDB vhosts and url rewriting for nice urls

http://westhoffswelt.de [email protected] slide: 10 / 35

Page 42: Developing CouchApps

CouchApp techniques

Store all application files as document attachments

Attachments can be stored for any document inside CouchDBCan be directly accesed using the RESTful interface

Use CouchDBs authentication backend for user management

Use validation function for access restrictions

Use show and list functions to output HTML

Access CouchDB using Javascript and XHR

Use CouchDB vhosts and url rewriting for nice urls

http://westhoffswelt.de [email protected] slide: 10 / 35

Page 43: Developing CouchApps

CouchApp techniques

Store all application files as document attachments

Attachments can be stored for any document inside CouchDBCan be directly accesed using the RESTful interface

Use CouchDBs authentication backend for user management

Use validation function for access restrictions

Use show and list functions to output HTML

Access CouchDB using Javascript and XHR

Use CouchDB vhosts and url rewriting for nice urls

http://westhoffswelt.de [email protected] slide: 10 / 35

Page 44: Developing CouchApps

CouchApp techniques

Store all application files as document attachments

Attachments can be stored for any document inside CouchDBCan be directly accesed using the RESTful interface

Use CouchDBs authentication backend for user management

Use validation function for access restrictions

Use show and list functions to output HTML

Access CouchDB using Javascript and XHR

Use CouchDB vhosts and url rewriting for nice urls

http://westhoffswelt.de [email protected] slide: 10 / 35

Page 45: Developing CouchApps

CouchApp techniques

Store all application files as document attachments

Attachments can be stored for any document inside CouchDBCan be directly accesed using the RESTful interface

Use CouchDBs authentication backend for user management

Use validation function for access restrictions

Use show and list functions to output HTML

Access CouchDB using Javascript and XHR

Use CouchDB vhosts and url rewriting for nice urls

http://westhoffswelt.de [email protected] slide: 10 / 35

Page 46: Developing CouchApps

Authentication backend: User Management

Managing users:

Futon:

RESTful API:

Create a new document in the users databasehttp://localhost:5984/ users/org.couchdb.user:foo

http://westhoffswelt.de [email protected] slide: 11 / 35

Page 47: Developing CouchApps

Authentication backend: User Management

Managing users:

Futon:

RESTful API:

Create a new document in the users databasehttp://localhost:5984/ users/org.couchdb.user:foo

http://westhoffswelt.de [email protected] slide: 11 / 35

Page 48: Developing CouchApps

Authentication backend: User Management

Managing users:

Futon:

RESTful API:

Create a new document in the users databasehttp://localhost:5984/ users/org.couchdb.user:foo

http://westhoffswelt.de [email protected] slide: 11 / 35

Page 49: Developing CouchApps

Authentication backend: Logging in (Cookie)

Logging in:

POST username and password to

http://localhost:5984/ session

Parameters user and password

application/x-www-form-urlencoded encoded

Post:

name=foo&password=bar

Response:

{”ok” : true , ”name” : ” foo ” , ” r o l e s ” : [ ] }

http://westhoffswelt.de [email protected] slide: 12 / 35

Page 50: Developing CouchApps

Authentication backend: Logging in (Cookie)

Logging in:

POST username and password to

http://localhost:5984/ session

Parameters user and password

application/x-www-form-urlencoded encoded

Post:

name=foo&password=bar

Response:

{”ok” : true , ”name” : ” foo ” , ” r o l e s ” : [ ] }

http://westhoffswelt.de [email protected] slide: 12 / 35

Page 51: Developing CouchApps

Authentication backend: Logging in (Cookie)

Logging in:

POST username and password to

http://localhost:5984/ session

Parameters user and password

application/x-www-form-urlencoded encoded

Post:

name=foo&password=bar

Response:

{”ok” : true , ”name” : ” foo ” , ” r o l e s ” : [ ] }

http://westhoffswelt.de [email protected] slide: 12 / 35

Page 52: Developing CouchApps

Authentication backend: Logging in (Cookie)

Logging in:

POST username and password to

http://localhost:5984/ session

Parameters user and password

application/x-www-form-urlencoded encoded

Post:

name=foo&password=bar

Response:

{”ok” : true , ”name” : ” foo ” , ” r o l e s ” : [ ] }

http://westhoffswelt.de [email protected] slide: 12 / 35

Page 53: Developing CouchApps

Authentication backend: Logging in (Cookie)

Logging in:

POST username and password to

http://localhost:5984/ session

Parameters user and password

application/x-www-form-urlencoded encoded

Post:

name=foo&password=bar

Response:

{”ok” : true , ”name” : ” foo ” , ” r o l e s ” : [ ] }

http://westhoffswelt.de [email protected] slide: 12 / 35

Page 54: Developing CouchApps

Excursion: Design documents

Design documents supply certain special functionallities per db

Stored with special id design/some-id

Multiple design documents allowed per database

Used to define:

View functions (Map&Reduce)List functionsShow functionsValidation functions. . .

http://westhoffswelt.de [email protected] slide: 13 / 35

Page 55: Developing CouchApps

Excursion: Design documents

Design documents supply certain special functionallities per db

Stored with special id design/some-id

Multiple design documents allowed per database

Used to define:

View functions (Map&Reduce)List functionsShow functionsValidation functions. . .

http://westhoffswelt.de [email protected] slide: 13 / 35

Page 56: Developing CouchApps

Excursion: Design documents

Design documents supply certain special functionallities per db

Stored with special id design/some-id

Multiple design documents allowed per database

Used to define:

View functions (Map&Reduce)List functionsShow functionsValidation functions. . .

http://westhoffswelt.de [email protected] slide: 13 / 35

Page 57: Developing CouchApps

Excursion: Design documents

Design documents supply certain special functionallities per db

Stored with special id design/some-id

Multiple design documents allowed per database

Used to define:

View functions (Map&Reduce)List functionsShow functionsValidation functions. . .

http://westhoffswelt.de [email protected] slide: 13 / 35

Page 58: Developing CouchApps

Excursion: Design documents

Design documents supply certain special functionallities per db

Stored with special id design/some-id

Multiple design documents allowed per database

Used to define:

View functions (Map&Reduce)List functionsShow functionsValidation functions. . .

http://westhoffswelt.de [email protected] slide: 13 / 35

Page 59: Developing CouchApps

Excursion: Design documents

Design documents supply certain special functionallities per db

Stored with special id design/some-id

Multiple design documents allowed per database

Used to define:

View functions (Map&Reduce)List functionsShow functionsValidation functions. . .

http://westhoffswelt.de [email protected] slide: 13 / 35

Page 60: Developing CouchApps

Excursion: Design documents

Design documents supply certain special functionallities per db

Stored with special id design/some-id

Multiple design documents allowed per database

Used to define:

View functions (Map&Reduce)List functionsShow functionsValidation functions. . .

http://westhoffswelt.de [email protected] slide: 13 / 35

Page 61: Developing CouchApps

Excursion: Design documents

Design documents supply certain special functionallities per db

Stored with special id design/some-id

Multiple design documents allowed per database

Used to define:

View functions (Map&Reduce)List functionsShow functionsValidation functions. . .

http://westhoffswelt.de [email protected] slide: 13 / 35

Page 62: Developing CouchApps

Excursion: Design documents

Design documents supply certain special functionallities per db

Stored with special id design/some-id

Multiple design documents allowed per database

Used to define:

View functions (Map&Reduce)List functionsShow functionsValidation functions. . .

http://westhoffswelt.de [email protected] slide: 13 / 35

Page 63: Developing CouchApps

Validation functions: Validate updates

Validation of document creations or updates using Javascriptfunctions

Registration: Property validate doc update on any designdocument

Multiple validation functions on different design documentspossible

Called one after anotherNo defined execution order: Functions need to be isolatedOne fails: validation fails

http://westhoffswelt.de [email protected] slide: 14 / 35

Page 64: Developing CouchApps

Validation functions: Validate updates

Validation of document creations or updates using Javascriptfunctions

Registration: Property validate doc update on any designdocument

Multiple validation functions on different design documentspossible

Called one after anotherNo defined execution order: Functions need to be isolatedOne fails: validation fails

http://westhoffswelt.de [email protected] slide: 14 / 35

Page 65: Developing CouchApps

Validation functions: Validate updates

Validation of document creations or updates using Javascriptfunctions

Registration: Property validate doc update on any designdocument

Multiple validation functions on different design documentspossible

Called one after anotherNo defined execution order: Functions need to be isolatedOne fails: validation fails

http://westhoffswelt.de [email protected] slide: 14 / 35

Page 66: Developing CouchApps

Validation functions: Validate updates

Validation of document creations or updates using Javascriptfunctions

Registration: Property validate doc update on any designdocument

Multiple validation functions on different design documentspossible

Called one after anotherNo defined execution order: Functions need to be isolatedOne fails: validation fails

http://westhoffswelt.de [email protected] slide: 14 / 35

Page 67: Developing CouchApps

Validation functions: Validate updates

Validation of document creations or updates using Javascriptfunctions

Registration: Property validate doc update on any designdocument

Multiple validation functions on different design documentspossible

Called one after anotherNo defined execution order: Functions need to be isolatedOne fails: validation fails

http://westhoffswelt.de [email protected] slide: 14 / 35

Page 68: Developing CouchApps

Validation functions: Validate updates

Validation of document creations or updates using Javascriptfunctions

Registration: Property validate doc update on any designdocument

Multiple validation functions on different design documentspossible

Called one after anotherNo defined execution order: Functions need to be isolatedOne fails: validation fails

http://westhoffswelt.de [email protected] slide: 14 / 35

Page 69: Developing CouchApps

Validation functions: Validate updates II

Example

Ensure all documents have a type fieldadded is not allowed to be changed after document creation

f u n c t i o n ( newDoc , oldDoc , u s e rC tx ) {i f ( ! newDoc . type ) {

throw ({ f o r b i d d e n : ”Mandatory f i e l d ’ t ype ’ i sm i s s i n g ” }) ;

}

i f ( oldDoc && toJSON( oldDoc . added ) != toJSON(newDoc. added ) ) {

throw ( . . . )}

}

http://westhoffswelt.de [email protected] slide: 15 / 35

Page 70: Developing CouchApps

Validation functions: Validate updates II

Example

Ensure all documents have a type fieldadded is not allowed to be changed after document creation

f u n c t i o n ( newDoc , oldDoc , u s e rC tx ) {i f ( ! newDoc . type ) {

throw ({ f o r b i d d e n : ”Mandatory f i e l d ’ t ype ’ i sm i s s i n g ” }) ;

}

i f ( oldDoc && toJSON( oldDoc . added ) != toJSON(newDoc. added ) ) {

throw ( . . . )}

}

http://westhoffswelt.de [email protected] slide: 15 / 35

Page 71: Developing CouchApps

Validation functions: Validate updates II

Example

Ensure all documents have a type fieldadded is not allowed to be changed after document creation

f u n c t i o n ( newDoc , oldDoc , u s e rC tx ) {i f ( ! newDoc . type ) {

throw ({ f o r b i d d e n : ”Mandatory f i e l d ’ t ype ’ i sm i s s i n g ” }) ;

}

i f ( oldDoc && toJSON( oldDoc . added ) != toJSON(newDoc. added ) ) {

throw ( . . . )}

}

http://westhoffswelt.de [email protected] slide: 15 / 35

Page 72: Developing CouchApps

Validation functions: Access control

Use validation doc update function as access controlsystem

Ensure the user is logged inEnsure username and author field are identical

f u n c t i o n ( newDoc , oldDoc , u s e rC tx ) {i f ( ! u s e rC tx . name ) {

throw ({ f o r b i d d e n : ”You need to be l ogged i n tochange documents . ” }) ;

}

i f ( ( oldDoc && use rCtx . name != oldDoc . au tho r ) | |use rCtx . name != newDoc . au tho r ) {

throw ( . . . )}

}

http://westhoffswelt.de [email protected] slide: 16 / 35

Page 73: Developing CouchApps

Validation functions: Access control

Use validation doc update function as access controlsystem

Ensure the user is logged inEnsure username and author field are identical

f u n c t i o n ( newDoc , oldDoc , u s e rC tx ) {i f ( ! u s e rC tx . name ) {

throw ({ f o r b i d d e n : ”You need to be l ogged i n tochange documents . ” }) ;

}

i f ( ( oldDoc && use rCtx . name != oldDoc . au tho r ) | |use rCtx . name != newDoc . au tho r ) {

throw ( . . . )}

}

http://westhoffswelt.de [email protected] slide: 16 / 35

Page 74: Developing CouchApps

Validation functions: Access control

Use validation doc update function as access controlsystem

Ensure the user is logged inEnsure username and author field are identical

f u n c t i o n ( newDoc , oldDoc , u s e rC tx ) {i f ( ! u s e rC tx . name ) {

throw ({ f o r b i d d e n : ”You need to be l ogged i n tochange documents . ” }) ;

}

i f ( ( oldDoc && use rCtx . name != oldDoc . au tho r ) | |use rCtx . name != newDoc . au tho r ) {

throw ( . . . )}

}

http://westhoffswelt.de [email protected] slide: 16 / 35

Page 75: Developing CouchApps

Show and list functions

User formatted data instead of plain JSON

Show functions format documents

List functions format views

Multiple show and list functions are allowedper-design-document

Stored as shows and lists object

” shows” : {”summary” : ” f u n c t i o n ( doc , r eq ) { . . . } ” ,” d e t a i l ” : ” f u n c t i o n ( doc , r eq ) { . . . } ”

}

http://westhoffswelt.de [email protected] slide: 17 / 35

Page 76: Developing CouchApps

Show and list functions

User formatted data instead of plain JSON

Show functions format documents

List functions format views

Multiple show and list functions are allowedper-design-document

Stored as shows and lists object

” shows” : {”summary” : ” f u n c t i o n ( doc , r eq ) { . . . } ” ,” d e t a i l ” : ” f u n c t i o n ( doc , r eq ) { . . . } ”

}

http://westhoffswelt.de [email protected] slide: 17 / 35

Page 77: Developing CouchApps

Show and list functions

User formatted data instead of plain JSON

Show functions format documents

List functions format views

Multiple show and list functions are allowedper-design-document

Stored as shows and lists object

” shows” : {”summary” : ” f u n c t i o n ( doc , r eq ) { . . . } ” ,” d e t a i l ” : ” f u n c t i o n ( doc , r eq ) { . . . } ”

}

http://westhoffswelt.de [email protected] slide: 17 / 35

Page 78: Developing CouchApps

Show and list functions

User formatted data instead of plain JSON

Show functions format documents

List functions format views

Multiple show and list functions are allowedper-design-document

Stored as shows and lists object

” shows” : {”summary” : ” f u n c t i o n ( doc , r eq ) { . . . } ” ,” d e t a i l ” : ” f u n c t i o n ( doc , r eq ) { . . . } ”

}

http://westhoffswelt.de [email protected] slide: 17 / 35

Page 79: Developing CouchApps

Show and list functions

User formatted data instead of plain JSON

Show functions format documents

List functions format views

Multiple show and list functions are allowedper-design-document

Stored as shows and lists object

” shows” : {”summary” : ” f u n c t i o n ( doc , r eq ) { . . . } ” ,” d e t a i l ” : ” f u n c t i o n ( doc , r eq ) { . . . } ”

}

http://westhoffswelt.de [email protected] slide: 17 / 35

Page 80: Developing CouchApps

Show function to output HTML

Arguments

doc - Document to be returnedreq - Request object

User contextGET parameterAccept header. . .

Return value is a response object

body - Content returned to the callerheaders - HTML headers (Can be used to set Content-Type)base64 - Can be used instead of body to send binary data

http://westhoffswelt.de [email protected] slide: 18 / 35

Page 81: Developing CouchApps

Show function to output HTML

Arguments

doc - Document to be returnedreq - Request object

User contextGET parameterAccept header. . .

Return value is a response object

body - Content returned to the callerheaders - HTML headers (Can be used to set Content-Type)base64 - Can be used instead of body to send binary data

http://westhoffswelt.de [email protected] slide: 18 / 35

Page 82: Developing CouchApps

Show function to output HTML

Arguments

doc - Document to be returnedreq - Request object

User contextGET parameterAccept header. . .

Return value is a response object

body - Content returned to the callerheaders - HTML headers (Can be used to set Content-Type)base64 - Can be used instead of body to send binary data

http://westhoffswelt.de [email protected] slide: 18 / 35

Page 83: Developing CouchApps

Show function to output HTML

Arguments

doc - Document to be returnedreq - Request object

User contextGET parameterAccept header. . .

Return value is a response object

body - Content returned to the callerheaders - HTML headers (Can be used to set Content-Type)base64 - Can be used instead of body to send binary data

http://westhoffswelt.de [email protected] slide: 18 / 35

Page 84: Developing CouchApps

Show function to output HTML

Arguments

doc - Document to be returnedreq - Request object

User contextGET parameterAccept header. . .

Return value is a response object

body - Content returned to the callerheaders - HTML headers (Can be used to set Content-Type)base64 - Can be used instead of body to send binary data

http://westhoffswelt.de [email protected] slide: 18 / 35

Page 85: Developing CouchApps

Show function to output HTML

Arguments

doc - Document to be returnedreq - Request object

User contextGET parameterAccept header. . .

Return value is a response object

body - Content returned to the callerheaders - HTML headers (Can be used to set Content-Type)base64 - Can be used instead of body to send binary data

http://westhoffswelt.de [email protected] slide: 18 / 35

Page 86: Developing CouchApps

Show function to output HTML

Arguments

doc - Document to be returnedreq - Request object

User contextGET parameterAccept header. . .

Return value is a response object

body - Content returned to the callerheaders - HTML headers (Can be used to set Content-Type)base64 - Can be used instead of body to send binary data

http://westhoffswelt.de [email protected] slide: 18 / 35

Page 87: Developing CouchApps

Show function to output HTML

Arguments

doc - Document to be returnedreq - Request object

User contextGET parameterAccept header. . .

Return value is a response object

body - Content returned to the callerheaders - HTML headers (Can be used to set Content-Type)base64 - Can be used instead of body to send binary data

http://westhoffswelt.de [email protected] slide: 18 / 35

Page 88: Developing CouchApps

Show function to output HTML

Arguments

doc - Document to be returnedreq - Request object

User contextGET parameterAccept header. . .

Return value is a response object

body - Content returned to the callerheaders - HTML headers (Can be used to set Content-Type)base64 - Can be used instead of body to send binary data

http://westhoffswelt.de [email protected] slide: 18 / 35

Page 89: Developing CouchApps

Show function to output HTML

Arguments

doc - Document to be returnedreq - Request object

User contextGET parameterAccept header. . .

Return value is a response object

body - Content returned to the callerheaders - HTML headers (Can be used to set Content-Type)base64 - Can be used instead of body to send binary data

http://westhoffswelt.de [email protected] slide: 18 / 35

Page 90: Developing CouchApps

Show function to output HTML

Arguments

doc - Document to be returnedreq - Request object

User contextGET parameterAccept header. . .

Return value is a response object

body - Content returned to the callerheaders - HTML headers (Can be used to set Content-Type)base64 - Can be used instead of body to send binary data

http://westhoffswelt.de [email protected] slide: 18 / 35

Page 91: Developing CouchApps

Show function to output HTML II

Example

Output document type and author as HTML

f u n c t i o n ( doc , r eq ) {

re tu rn {body : [

”<h1>The ” ,doc . type ,” document has been c r e a t e d by ” ,doc . author ,”</h1>”

] . j o i n ( ”” ) ;} ;

}

http://westhoffswelt.de [email protected] slide: 19 / 35

Page 92: Developing CouchApps

Show function to output HTML II

Example

Output document type and author as HTML

f u n c t i o n ( doc , r eq ) {

re tu rn {body : [

”<h1>The ” ,doc . type ,” document has been c r e a t e d by ” ,doc . author ,”</h1>”

] . j o i n ( ”” ) ;} ;

}

http://westhoffswelt.de [email protected] slide: 19 / 35

Page 93: Developing CouchApps

Show function to output HTML II

Example

Output document type and author as HTML

f u n c t i o n ( doc , r eq ) {

re tu rn {body : [

”<h1>The ” ,doc . type ,” document has been c r e a t e d by ” ,doc . author ,”</h1>”

] . j o i n ( ”” ) ;} ;

}

http://westhoffswelt.de [email protected] slide: 19 / 35

Page 94: Developing CouchApps

List functions: Streaming API

Arguments

head - Statistical data about the viewreq - Request object

Return value is not used

Streaming API

getRow() - Retrieve next row from the view, or null at the endsend(data) - Send out the next piece of data to the caller

http://westhoffswelt.de [email protected] slide: 20 / 35

Page 95: Developing CouchApps

List functions: Streaming API

Arguments

head - Statistical data about the viewreq - Request object

Return value is not used

Streaming API

getRow() - Retrieve next row from the view, or null at the endsend(data) - Send out the next piece of data to the caller

http://westhoffswelt.de [email protected] slide: 20 / 35

Page 96: Developing CouchApps

List functions: Streaming API

Arguments

head - Statistical data about the viewreq - Request object

Return value is not used

Streaming API

getRow() - Retrieve next row from the view, or null at the endsend(data) - Send out the next piece of data to the caller

http://westhoffswelt.de [email protected] slide: 20 / 35

Page 97: Developing CouchApps

List functions: Streaming API

Arguments

head - Statistical data about the viewreq - Request object

Return value is not used

Streaming API

getRow() - Retrieve next row from the view, or null at the endsend(data) - Send out the next piece of data to the caller

http://westhoffswelt.de [email protected] slide: 20 / 35

Page 98: Developing CouchApps

List functions: Streaming API

Arguments

head - Statistical data about the viewreq - Request object

Return value is not used

Streaming API

getRow() - Retrieve next row from the view, or null at the endsend(data) - Send out the next piece of data to the caller

http://westhoffswelt.de [email protected] slide: 20 / 35

Page 99: Developing CouchApps

List functions: Streaming API

Arguments

head - Statistical data about the viewreq - Request object

Return value is not used

Streaming API

getRow() - Retrieve next row from the view, or null at the endsend(data) - Send out the next piece of data to the caller

http://westhoffswelt.de [email protected] slide: 20 / 35

Page 100: Developing CouchApps

List functions: Streaming API

Arguments

head - Statistical data about the viewreq - Request object

Return value is not used

Streaming API

getRow() - Retrieve next row from the view, or null at the endsend(data) - Send out the next piece of data to the caller

http://westhoffswelt.de [email protected] slide: 20 / 35

Page 101: Developing CouchApps

List functions: Example

Example

Output authors in list as unordered HTML list

f u n c t i o n ( head , r eq ) {va r cu r ;

send ( ’<ul> ’ ) ;

whi le ( cu r = getRow ( ) ) {send ( ’< l i > ’ + cur . au tho r + ’</ l i > ’ ) ;

}

send ( ’</ul> ’ ) ;}

http://westhoffswelt.de [email protected] slide: 21 / 35

Page 102: Developing CouchApps

List functions: Example

Example

Output authors in list as unordered HTML list

f u n c t i o n ( head , r eq ) {va r cu r ;

send ( ’<ul> ’ ) ;

whi le ( cu r = getRow ( ) ) {send ( ’< l i > ’ + cur . au tho r + ’</ l i > ’ ) ;

}

send ( ’</ul> ’ ) ;}

http://westhoffswelt.de [email protected] slide: 21 / 35

Page 103: Developing CouchApps

List functions: Example

Example

Output authors in list as unordered HTML list

f u n c t i o n ( head , r eq ) {va r cu r ;

send ( ’<ul> ’ ) ;

whi le ( cu r = getRow ( ) ) {send ( ’< l i > ’ + cur . au tho r + ’</ l i > ’ ) ;

}

send ( ’</ul> ’ ) ;}

http://westhoffswelt.de [email protected] slide: 21 / 35

Page 104: Developing CouchApps

Query show and list functions

Queried based on design document and name

Show functions

GET /db/ design/mydesign/ show/show-name/doc-id

List functions

GET /db/ design/mydesign/ list/list-name/view-name

http://westhoffswelt.de [email protected] slide: 22 / 35

Page 105: Developing CouchApps

Query show and list functions

Queried based on design document and name

Show functions

GET /db/ design/mydesign/ show/show-name/doc-id

List functions

GET /db/ design/mydesign/ list/list-name/view-name

http://westhoffswelt.de [email protected] slide: 22 / 35

Page 106: Developing CouchApps

Query show and list functions

Queried based on design document and name

Show functions

GET /db/ design/mydesign/ show/show-name/doc-id

List functions

GET /db/ design/mydesign/ list/list-name/view-name

http://westhoffswelt.de [email protected] slide: 22 / 35

Page 107: Developing CouchApps

Show and list functions in real applications

Use a templating system

Javscript micro template language based on John Resigs ideahttp://github.com/furf/jquery-template

Use integrated provides and registerType functions toserve multiple formats based on the accept header

Maybe do some sort of user authentication before showingcontent

http://westhoffswelt.de [email protected] slide: 23 / 35

Page 108: Developing CouchApps

Show and list functions in real applications

Use a templating system

Javscript micro template language based on John Resigs ideahttp://github.com/furf/jquery-template

Use integrated provides and registerType functions toserve multiple formats based on the accept header

Maybe do some sort of user authentication before showingcontent

http://westhoffswelt.de [email protected] slide: 23 / 35

Page 109: Developing CouchApps

Show and list functions in real applications

Use a templating system

Javscript micro template language based on John Resigs ideahttp://github.com/furf/jquery-template

Use integrated provides and registerType functions toserve multiple formats based on the accept header

Maybe do some sort of user authentication before showingcontent

http://westhoffswelt.de [email protected] slide: 23 / 35

Page 110: Developing CouchApps

Show and list functions in real applications

Use a templating system

Javscript micro template language based on John Resigs ideahttp://github.com/furf/jquery-template

Use integrated provides and registerType functions toserve multiple formats based on the accept header

Maybe do some sort of user authentication before showingcontent

http://westhoffswelt.de [email protected] slide: 23 / 35

Page 111: Developing CouchApps

Url rewriting

Urls like this one are neither readable nor usable

/db/ design/mydesign/ list/list-name/view-name?limit=5

CouchDB supports internal url rewriting

Defined as array of rewrites on any design document

” r e w r i t e s ” : [{

” from” : ”/ i ndex ” ,” to ” : ” l i s t / l i s t −name/view−name? l i m i t=5”

}]

http://westhoffswelt.de [email protected] slide: 24 / 35

Page 112: Developing CouchApps

Url rewriting

Urls like this one are neither readable nor usable

/db/ design/mydesign/ list/list-name/view-name?limit=5

CouchDB supports internal url rewriting

Defined as array of rewrites on any design document

” r e w r i t e s ” : [{

” from” : ”/ i ndex ” ,” to ” : ” l i s t / l i s t −name/view−name? l i m i t=5”

}]

http://westhoffswelt.de [email protected] slide: 24 / 35

Page 113: Developing CouchApps

Url rewriting

Urls like this one are neither readable nor usable

/db/ design/mydesign/ list/list-name/view-name?limit=5

CouchDB supports internal url rewriting

Defined as array of rewrites on any design document

” r e w r i t e s ” : [{

” from” : ”/ i ndex ” ,” to ” : ” l i s t / l i s t −name/view−name? l i m i t=5”

}]

http://westhoffswelt.de [email protected] slide: 24 / 35

Page 114: Developing CouchApps

Url rewriting

Urls like this one are neither readable nor usable

/db/ design/mydesign/ list/list-name/view-name?limit=5

CouchDB supports internal url rewriting

Defined as array of rewrites on any design document

” r e w r i t e s ” : [{

” from” : ”/ i ndex ” ,” to ” : ” l i s t / l i s t −name/view−name? l i m i t=5”

}]

http://westhoffswelt.de [email protected] slide: 24 / 35

Page 115: Developing CouchApps

Advanced url rewriting

Using named placeholders

Match each path segment

” from” : ”/ en t r y / : doc” ,” to ” : ” show/show−name / : doc”

Using match all at the end of an url

Appends given query parameters

” from” : ”/ en t r y /∗” ,” to ” : ” show/show−name/∗”

http://westhoffswelt.de [email protected] slide: 25 / 35

Page 116: Developing CouchApps

Advanced url rewriting

Using named placeholders

Match each path segment

” from” : ”/ en t r y / : doc” ,” to ” : ” show/show−name / : doc”

Using match all at the end of an url

Appends given query parameters

” from” : ”/ en t r y /∗” ,” to ” : ” show/show−name/∗”

http://westhoffswelt.de [email protected] slide: 25 / 35

Page 117: Developing CouchApps

Advanced url rewriting II

Rewriting to query parameters

” from” : ”/page / : s t a r t ” ,” to ” : ” l i s t / l i s t −name/ pages ” ,” query ” : {

” s t a r t k e y ” : ” : s t a r t ”}

Adress a context outside of the design document

Targets are always relative to the design documentRelative navigation with .. is allowed

” from” : ”/ raw / : doc” ,” to ” : ” . . / . . / : doc”

http://westhoffswelt.de [email protected] slide: 26 / 35

Page 118: Developing CouchApps

Advanced url rewriting II

Rewriting to query parameters

” from” : ”/page / : s t a r t ” ,” to ” : ” l i s t / l i s t −name/ pages ” ,” query ” : {

” s t a r t k e y ” : ” : s t a r t ”}

Adress a context outside of the design document

Targets are always relative to the design documentRelative navigation with .. is allowed

” from” : ”/ raw / : doc” ,” to ” : ” . . / . . / : doc”

http://westhoffswelt.de [email protected] slide: 26 / 35

Page 119: Developing CouchApps

Advanced url rewriting III

Rewriting based on HTTP methods

{” from” : ”/ en t r y /∗” ,” to ” : ” show/show−name/∗” ,”method” : ”GET”

} ,{

” from” : ”/ en t r y /∗” ,” to ” : ” update /update−name/∗” ,”method” : ”POST”

} ,

http://westhoffswelt.de [email protected] slide: 27 / 35

Page 120: Developing CouchApps

Query rewritten urls

Queried on design document using special rewrite path

/db/ design/mydesign/ rewrite/some-url

Better, but far from being perfect → Vhost configuration

http://westhoffswelt.de [email protected] slide: 28 / 35

Page 121: Developing CouchApps

Query rewritten urls

Queried on design document using special rewrite path

/db/ design/mydesign/ rewrite/some-url

Better, but far from being perfect → Vhost configuration

http://westhoffswelt.de [email protected] slide: 28 / 35

Page 122: Developing CouchApps

Query rewritten urls

Queried on design document using special rewrite path

/db/ design/mydesign/ rewrite/some-url

Better, but far from being perfect → Vhost configuration

http://westhoffswelt.de [email protected] slide: 28 / 35

Page 123: Developing CouchApps

Vhost configuration

CouchDB supports url changing based on the provided Host

Custom root path for every host/domain

Configured in local.ini

Direct all requests to the rewrite handler

[ v h o s t s ]example . com = /mydb/ d e s i g n /mydes ign / r e w r i t e

http://westhoffswelt.de [email protected] slide: 29 / 35

Page 124: Developing CouchApps

Vhost configuration

CouchDB supports url changing based on the provided Host

Custom root path for every host/domain

Configured in local.ini

Direct all requests to the rewrite handler

[ v h o s t s ]example . com = /mydb/ d e s i g n /mydes ign / r e w r i t e

http://westhoffswelt.de [email protected] slide: 29 / 35

Page 125: Developing CouchApps

Vhost configuration

CouchDB supports url changing based on the provided Host

Custom root path for every host/domain

Configured in local.ini

Direct all requests to the rewrite handler

[ v h o s t s ]example . com = /mydb/ d e s i g n /mydes ign / r e w r i t e

http://westhoffswelt.de [email protected] slide: 29 / 35

Page 126: Developing CouchApps

Vhost configuration

CouchDB supports url changing based on the provided Host

Custom root path for every host/domain

Configured in local.ini

Direct all requests to the rewrite handler

[ v h o s t s ]example . com = /mydb/ d e s i g n /mydes ign / r e w r i t e

http://westhoffswelt.de [email protected] slide: 29 / 35

Page 127: Developing CouchApps

Using CouchApp for deployment

CouchApp does not only categorize these application type

It is a utillity written in Python

http://github.com/couchapp/couchapp

Deployment system for CouchApps to CouchDBs

Providing some common widgets like login or profile

http://westhoffswelt.de [email protected] slide: 30 / 35

Page 128: Developing CouchApps

Using CouchApp for deployment

CouchApp does not only categorize these application type

It is a utillity written in Python

http://github.com/couchapp/couchapp

Deployment system for CouchApps to CouchDBs

Providing some common widgets like login or profile

http://westhoffswelt.de [email protected] slide: 30 / 35

Page 129: Developing CouchApps

Using CouchApp for deployment

CouchApp does not only categorize these application type

It is a utillity written in Python

http://github.com/couchapp/couchapp

Deployment system for CouchApps to CouchDBs

Providing some common widgets like login or profile

http://westhoffswelt.de [email protected] slide: 30 / 35

Page 130: Developing CouchApps

Using CouchApp for deployment

CouchApp does not only categorize these application type

It is a utillity written in Python

http://github.com/couchapp/couchapp

Deployment system for CouchApps to CouchDBs

Providing some common widgets like login or profile

http://westhoffswelt.de [email protected] slide: 30 / 35

Page 131: Developing CouchApps

CouchApp: Folder structure

Organize your applications into a special folder structure

.|−− a t tachment s|−− i d|−− l i s t s|−− r e w r i t e s|−− shows| ‘−− myshow . j s|−− updates|−− v a l i d a t e d o c u p d a t e . j s‘−− v i ews

‘−− myview|−− map . j s‘−− r educe . j s

http://westhoffswelt.de [email protected] slide: 31 / 35

Page 132: Developing CouchApps

CouchApp: Javascript preprocessing

CouchApps preprocesses Javascript before deploying it

Provides two useful macros: !code and !json

// !code lib/helper/validation utillities.jsInclude Javascript code from any other fileReuse code throughout your application functions

// !json lib.templates.mytemplateDot notation of path to .json fileAvailable using the full object path:lib.templates.mytemplate

http://westhoffswelt.de [email protected] slide: 32 / 35

Page 133: Developing CouchApps

CouchApp: Javascript preprocessing

CouchApps preprocesses Javascript before deploying it

Provides two useful macros: !code and !json

// !code lib/helper/validation utillities.jsInclude Javascript code from any other fileReuse code throughout your application functions

// !json lib.templates.mytemplateDot notation of path to .json fileAvailable using the full object path:lib.templates.mytemplate

http://westhoffswelt.de [email protected] slide: 32 / 35

Page 134: Developing CouchApps

CouchApp: Javascript preprocessing

CouchApps preprocesses Javascript before deploying it

Provides two useful macros: !code and !json

// !code lib/helper/validation utillities.jsInclude Javascript code from any other fileReuse code throughout your application functions

// !json lib.templates.mytemplateDot notation of path to .json fileAvailable using the full object path:lib.templates.mytemplate

http://westhoffswelt.de [email protected] slide: 32 / 35

Page 135: Developing CouchApps

CouchApp: Javascript preprocessing

CouchApps preprocesses Javascript before deploying it

Provides two useful macros: !code and !json

// !code lib/helper/validation utillities.jsInclude Javascript code from any other fileReuse code throughout your application functions

// !json lib.templates.mytemplateDot notation of path to .json fileAvailable using the full object path:lib.templates.mytemplate

http://westhoffswelt.de [email protected] slide: 32 / 35

Page 136: Developing CouchApps

CouchApp: Javascript preprocessing

CouchApps preprocesses Javascript before deploying it

Provides two useful macros: !code and !json

// !code lib/helper/validation utillities.jsInclude Javascript code from any other fileReuse code throughout your application functions

// !json lib.templates.mytemplateDot notation of path to .json fileAvailable using the full object path:lib.templates.mytemplate

http://westhoffswelt.de [email protected] slide: 32 / 35

Page 137: Developing CouchApps

CouchApp: Javascript preprocessing

CouchApps preprocesses Javascript before deploying it

Provides two useful macros: !code and !json

// !code lib/helper/validation utillities.jsInclude Javascript code from any other fileReuse code throughout your application functions

// !json lib.templates.mytemplateDot notation of path to .json fileAvailable using the full object path:lib.templates.mytemplate

http://westhoffswelt.de [email protected] slide: 32 / 35

Page 138: Developing CouchApps

CouchApp: Deployment

Specifying all parameters on the commandline

couchapp push http://user:pw@localhost:5984/mydb

Use .couchapprc file

{” env” : {

” d e f a u l t ” : {”db” : ” h t tp : // u s e r : pw@ loca lho s t :5984/mydb−dev”

} ,” p r oduc t i o n ” : {

”db” : ” h t tp :/// u s e r : pw@example . com/mydb”}

}}

http://westhoffswelt.de [email protected] slide: 33 / 35

Page 139: Developing CouchApps

CouchApp: Deployment

Specifying all parameters on the commandline

couchapp push http://user:pw@localhost:5984/mydb

Use .couchapprc file

{” env” : {

” d e f a u l t ” : {”db” : ” h t tp : // u s e r : pw@ loca lho s t :5984/mydb−dev”

} ,” p r oduc t i o n ” : {

”db” : ” h t tp :/// u s e r : pw@example . com/mydb”}

}}

http://westhoffswelt.de [email protected] slide: 33 / 35

Page 140: Developing CouchApps

Further reading

Things we didn’t have time to discussUpdate functions

http://wiki.apache.org/couchdb/Document Update Handlers

View functions

http://wiki.apache.org/couchdb/Introduction to CouchDB views

changes stream

http://books.couchdb.org/relax/reference/change-notifications

Evently javascript library

http://vimeo.com/9847214

Further documentationCouchDB: The definitive guide

http://books.couchdb.org/relax/

The CouchDB wiki

http://wiki.apache.org/couchdb/

http://westhoffswelt.de [email protected] slide: 34 / 35

Page 141: Developing CouchApps

Further reading

Things we didn’t have time to discussUpdate functions

http://wiki.apache.org/couchdb/Document Update Handlers

View functions

http://wiki.apache.org/couchdb/Introduction to CouchDB views

changes stream

http://books.couchdb.org/relax/reference/change-notifications

Evently javascript library

http://vimeo.com/9847214

Further documentationCouchDB: The definitive guide

http://books.couchdb.org/relax/

The CouchDB wiki

http://wiki.apache.org/couchdb/

http://westhoffswelt.de [email protected] slide: 34 / 35

Page 142: Developing CouchApps

Further reading

Things we didn’t have time to discussUpdate functions

http://wiki.apache.org/couchdb/Document Update Handlers

View functions

http://wiki.apache.org/couchdb/Introduction to CouchDB views

changes stream

http://books.couchdb.org/relax/reference/change-notifications

Evently javascript library

http://vimeo.com/9847214

Further documentationCouchDB: The definitive guide

http://books.couchdb.org/relax/

The CouchDB wiki

http://wiki.apache.org/couchdb/

http://westhoffswelt.de [email protected] slide: 34 / 35

Page 143: Developing CouchApps

Further reading

Things we didn’t have time to discussUpdate functions

http://wiki.apache.org/couchdb/Document Update Handlers

View functions

http://wiki.apache.org/couchdb/Introduction to CouchDB views

changes stream

http://books.couchdb.org/relax/reference/change-notifications

Evently javascript library

http://vimeo.com/9847214

Further documentationCouchDB: The definitive guide

http://books.couchdb.org/relax/

The CouchDB wiki

http://wiki.apache.org/couchdb/

http://westhoffswelt.de [email protected] slide: 34 / 35

Page 144: Developing CouchApps

Further reading

Things we didn’t have time to discussUpdate functions

http://wiki.apache.org/couchdb/Document Update Handlers

View functions

http://wiki.apache.org/couchdb/Introduction to CouchDB views

changes stream

http://books.couchdb.org/relax/reference/change-notifications

Evently javascript library

http://vimeo.com/9847214

Further documentationCouchDB: The definitive guide

http://books.couchdb.org/relax/

The CouchDB wiki

http://wiki.apache.org/couchdb/

http://westhoffswelt.de [email protected] slide: 34 / 35

Page 145: Developing CouchApps

Further reading

Things we didn’t have time to discussUpdate functions

http://wiki.apache.org/couchdb/Document Update Handlers

View functions

http://wiki.apache.org/couchdb/Introduction to CouchDB views

changes stream

http://books.couchdb.org/relax/reference/change-notifications

Evently javascript library

http://vimeo.com/9847214

Further documentationCouchDB: The definitive guide

http://books.couchdb.org/relax/

The CouchDB wiki

http://wiki.apache.org/couchdb/

http://westhoffswelt.de [email protected] slide: 34 / 35

Page 146: Developing CouchApps

Further reading

Things we didn’t have time to discussUpdate functions

http://wiki.apache.org/couchdb/Document Update Handlers

View functions

http://wiki.apache.org/couchdb/Introduction to CouchDB views

changes stream

http://books.couchdb.org/relax/reference/change-notifications

Evently javascript library

http://vimeo.com/9847214

Further documentationCouchDB: The definitive guide

http://books.couchdb.org/relax/

The CouchDB wiki

http://wiki.apache.org/couchdb/

http://westhoffswelt.de [email protected] slide: 34 / 35

Page 147: Developing CouchApps

Thanks for listening

Questions, comments or annotations?

Slides: http://westhoffswelt.de/portfolio.htm

Contact: Jakob Westhoff <[email protected]>Twitter: @jakobwesthoff

Please leave comments and vote at: http://joind.in/1612

http://westhoffswelt.de [email protected] slide: 35 / 35