A talk I did at phpday.it in Verona, Italy. Using some more advanced CouchDB functionality, like filters, changes feed, shows, geolocation (GeoCouch), and other interesting stuff. It also covers some real use cases.
21. “[The NoSQL movement] departs from the relational
model altogether, it should therefore have been called
more appropriately ‘NoREL’, or something to that
effect.”
- Carlo Strozzi
54. DEFINITION
“Replication is the process of sharing information so
as to ensure consistency between redundant
resources, such as software or hardware components,
to improve reliability, fault-tolerance, or accessibility.”
Source: wikipedia
66. IDG US IDG AUSTRALIA
CouchDB
relax
CouchDB
relax
CouchDB
relax
CouchDB
relax
CouchDB
relax
CouchDB
relax
CouchDB
relax
IDG NL IDG DE
67. IDG DE IDG Italy IDG Poland IDG Hungary
IDG NL IDG US IDG Romania IDG Sweden
IDG Brazil IDG UK IDG Spania IDG Portugal
IDG Ghana IDG Japan IDG Thailand IDG Vietnam
68. IMPLICATION
Every single bit of IDG content published
worldwide, is available anywhere, anytime in msec.
75. CHALLENGES
• Large amounts of data
• Large views (with big/long map/reduce queries)
• LOTS of traffic
• Location based partitions
• For fun and profit
95. NOSQL && SQL HYBRID
• onSave, onCommit hooks available in every major framework
• onSave -> make a JSON representation of your object, and
PUT it to couchdb (#protip: only ‘public’ data)
• sql db is leading, you don’t care about versioning in couchdb
• youcan use your data directly from couchdb within your
frontend javascript
96. MODEL
<?php
class Pony extends Application_models
{
public function toArray()
{
$data = $this->_getData();
// we don't want any private data pushed
unset($data['created_on']);
unset($data['created_by']);
unset($data['access_level']);
unset($data['private_data']);
$data['tags'] = $this->getTags();
$data['categories'] = $this->getCategories();
$data['rainbows'] = 'double';
return $data;
}
}
97. AFTER_SAVE
<?php
class article_module extends admin_module
{
public function after_save()
{
parent::after_save();
$data = $this->toJson();
// store the document in couchdb
$res = CouchDB::put($data);
// set the local id and revision, so we can
// use it the next time
$this->_id = $res->_id;
$this->_rev = $res->_rev;
}
}
158. GEOCOUCH
• Supports bbox, polygon, lines, etc.
• fork (for now)
• outputs via lists, georss possible
• directly useable by google maps
• can read GIS data
• combined with _changes makes interesting use cases possible