GTALUG Presentation on CouchDB

53
Who am I?

description

 

Transcript of GTALUG Presentation on CouchDB

Page 1: GTALUG Presentation on CouchDB

Who am I?

Page 2: GTALUG Presentation on CouchDB

Myles Braithwaite

Page 3: GTALUG Presentation on CouchDB
Page 4: GTALUG Presentation on CouchDB

We Develop Websites

Page 5: GTALUG Presentation on CouchDB

What is CouchDB?

Page 6: GTALUG Presentation on CouchDB

Erlang

Page 7: GTALUG Presentation on CouchDB

Apache CouchDB is a distributed, fault-tolerant and schema-free document-oriented database accessible via a RESTful HTTP/JSON API. Among other features, it provides robust, incremental replication with bi-directional conflict detection and resolution, and is queryable and indexable using a table-oriented view engine with JavaScript acting as the default view definition language.

Quote from http://couchdb.org/.

Page 8: GTALUG Presentation on CouchDB

Document-Oriented Database

Page 9: GTALUG Presentation on CouchDB

• Each record is store as a document.

• Any number of fields of any length.

• Fields can also contain multiple pieces of data.

Page 10: GTALUG Presentation on CouchDB

<people> <person first_name="Myles" last_name="Braithwaite"> <emails> <email value="[email protected]"/> <email value="[email protected]"/> </emails> </person></people>

Page 11: GTALUG Presentation on CouchDB

[ { "first_name": "Myles", "last_name": "Braithwaite", "emails": [ { "email": "[email protected]" }, { "email": "[email protected]" } ] }]

Page 12: GTALUG Presentation on CouchDB

Relational Database it would require two tables

Page 13: GTALUG Presentation on CouchDB

What is RESTful HTTP?

Page 14: GTALUG Presentation on CouchDB

Does anyone not know what HTTP is?

Page 15: GTALUG Presentation on CouchDB

REST

• Representational State Transfer

• The foundation of all Web Services

• SOAP,

• XML-RPC,

• and basic HTTP methods like:

• POST, GET, PUT, DELETE

Page 16: GTALUG Presentation on CouchDB

RESTful HTTP Methods CRUD

POST Create, Update & Delete

GET Read

PUT Create & Replace

DELETE Delete

Page 17: GTALUG Presentation on CouchDB

“Django may be built for the Web, but CouchDB is built of the Web. I’ve never seen software that so completely embraces the philosophies behind HTTP. CouchDB makes Django look old-school in the same way that Django makes ASP look outdated.”

— Jacob Kaplan-Moss, Django Developer

Page 18: GTALUG Presentation on CouchDB

What is JSON?

Page 19: GTALUG Presentation on CouchDB

• JavaScript version of XML.

Page 20: GTALUG Presentation on CouchDB

• A less dramatic/lightweight version of XML.

Page 21: GTALUG Presentation on CouchDB

• Google and Yahoo are using it in there Web Services.

Page 22: GTALUG Presentation on CouchDB

Distributed

Page 23: GTALUG Presentation on CouchDB
Page 24: GTALUG Presentation on CouchDB
Page 25: GTALUG Presentation on CouchDB

Bi-Directional Conflict Detection and

Resolution

Page 26: GTALUG Presentation on CouchDB

Bi-Directional Conflict Detection and

Resolution

Page 27: GTALUG Presentation on CouchDB

Bi-Directional Conflict Detection and

Resolution

Page 28: GTALUG Presentation on CouchDB

Query Documents with JavaScript

Page 29: GTALUG Presentation on CouchDB

Views

Page 30: GTALUG Presentation on CouchDB

• Map Functions

• Reduce Functions

• Lookup Views -- Demo

• Complex Keys -- Demo

Page 31: GTALUG Presentation on CouchDB

function(doc) {emit(null, doc);}

Map Functions

Page 32: GTALUG Presentation on CouchDB

function(doc) { if (doc.first_name && doc.last_name) { var full_name = (doc.first_name + " " + doc.last_name) emit(full_name, doc); }};

Text

Map Functions

Page 33: GTALUG Presentation on CouchDB

Reduce Functions

function (key, values, rereduce) { return sum(values);}

Page 34: GTALUG Presentation on CouchDB

Futon

Page 35: GTALUG Presentation on CouchDB

Basically the PHPMyAdmin for

CouchDB

Page 36: GTALUG Presentation on CouchDB

Demo Time

Page 37: GTALUG Presentation on CouchDB

$ curl -X PUT -v 'http://127.0.0.1:5984/temp_database/'

> PUT /temp_database/ HTTP/1.1> User-Agent: curl> Host: 127.0.0.1:5984> Accept: */*> < HTTP/1.1 201 Created< Server: CouchDB< Date: Tue, 09 Dec 2008 20:32:15 GMT< Content-Type: text/plain;charset=utf-8< Content-Length: 11< {"ok":true}

Page 38: GTALUG Presentation on CouchDB

$ curl -X DELETE -v 'http://127.0.0.1:5984/temp_database/'

> DELETE /temp_database/ HTTP/1.1> User-Agent: curl> Host: 127.0.0.1:5984> Accept: */*> < HTTP/1.1 200 OK< Server: CouchDB< Date: Tue, 09 Dec 2008 20:35:26 GMT< Content-Type: text/plain;charset=utf-8< Content-Length: 11< {"ok":true}

Page 39: GTALUG Presentation on CouchDB

$ curl 'http://127.0.0.1:5984/'

{"couchdb":"Welcome","version":"0.8.1-incubating"}

Page 40: GTALUG Presentation on CouchDB

$ curl 'http://127.0.0.1:5984/address_book/'

{"db_name":"address_book","doc_count":18,"doc_del_count":2,"update_seq":117,"compact_running":false,"disk_size":242905}

Page 41: GTALUG Presentation on CouchDB

$ curl 'http://127.0.0.1:5984/address_book/_all_docs/'

{"total_rows":18,"offset":0,"rows":[{"id":"1074d8805eaa79dfec356d34aa719a95","key":"1074d8805eaa79dfec356d34aa719a95","value":{"rev":"3720758831"}},...

Page 42: GTALUG Presentation on CouchDB

$ curl 'http://127.0.0.1:5984/address_book/_all_docs?count=1'

{"total_rows":18,"offset":0,"rows":[{"id":"1074d8805eaa79dfec356d34aa719a95","key":"1074d8805eaa79dfec356d34aa719a95","value":{"rev":"3720758831"}}]}

Page 44: GTALUG Presentation on CouchDB

$ curl 'http://127.0.0.1:5984/address_book/1074d8805eaa79dfec356d34aa719a95?rev=3720758831'

Page 46: GTALUG Presentation on CouchDB

$ curl 'http://127.0.0.1:5984/address_book/_view/contacts/contact_list/'

{"total_rows":5,"offset":0,"rows":[{"id":"93a31f6756545d9d59ca53fba6f92fe0","key":"Myles Braithwaite","value":{"_id":"93a31f6756545d9d59ca53fba6f92fe0","_rev":"3685624062","fn":{"family-name":"Braithwaite","given-name":"Myles"},"email":[{"value":"[email protected]","type":"Personal"},{"value":"[email protected]","type":"Work"}],"org":{"organization-name":"Monkey in your Soul"}}}...

Page 47: GTALUG Presentation on CouchDB

Use Cases

Page 48: GTALUG Presentation on CouchDB
Page 49: GTALUG Presentation on CouchDB
Page 50: GTALUG Presentation on CouchDB
Page 51: GTALUG Presentation on CouchDB
Page 52: GTALUG Presentation on CouchDB

What CouchDB should not be used for!

• A relational database.

• A replacement for relational databases.

• An object-oriented database. Or more specifically, meant to function as a seamless persistence layer for an OO programming language.

Page 53: GTALUG Presentation on CouchDB

Pictures• http://flickr.com/photos/

83737641@N00/2377691249/

• http://flickr.com/photos/dragon2309/1490657223/

• http://flickr.com/photos/herzogbr/359841353/

• http://flickr.com/photos/irisheyes/1160297224/

• http://flickr.com/photos/jessefriedman/1435220149/

• http://flickr.com/photos/tomnatt/2763592134/

• http://flickr.com/photos/theo_reth/188334429/

• http://flickr.com/photos/photonquantique/2596581870/

• http://flickr.com/photos/malcolmtredinnick/202679799/

• http://flickr.com/photos/andrewmoir/3012531/

• http://flickr.com/photos/apesara/2499666202/

• http://flickr.com/photos/mehrwert/18711050/

• http://flickr.com/photos/bohemianrabbit/2815366720/

• http://flickr.com/photos/ianturton/2155423758/

• http://flickr.com/photos/mbiddulph/2037845171/

• http://flickr.com/photos/cgc/130309167/

• http://www.flickr.com/photos/daveaustria/2654190796