relax your project with couchdb
DESCRIPTION
Talk given at djangocon.eu 2010 berlinTRANSCRIPT
![Page 1: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/1.jpg)
Relax your project with CouchDB
Benoît Chesneau26/05/2010 - djangocon berlin
Wednesday, May 26, 2010
![Page 2: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/2.jpg)
• Why using a “NoSQL” solution ?
• CouchDB ?
• CouchDBKit: CouchDB & Django
Wednesday, May 26, 2010
![Page 3: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/3.jpg)
• CouchDB developer• Maintainer of CouchDBkit,
Couchbeam, Couchapp , couchdbproxy, ...
Why i’m here
Wednesday, May 26, 2010
![Page 4: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/4.jpg)
• We don’t need “scalability” sometimes• Most of DB size < 300 GB (2 GB)• All my data could be on a machine
(comcast)• Often, DB requests are fast enough
Why NOSQL ?
Wednesday, May 26, 2010
![Page 5: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/5.jpg)
Agile
• Different kinds of data• Easy denormalisation• Migrate your data easily• Keep your data safe• Flexibility, Simplicity
Wednesday, May 26, 2010
![Page 6: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/6.jpg)
KEEP YOUR DATA SAFE
Wednesday, May 26, 2010
![Page 7: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/7.jpg)
Order Customer Delivery
Item Item
Ex. Shop
Wednesday, May 26, 2010
![Page 8: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/8.jpg)
• Oriented Document Database• REST• Map/Reduce (M/R)• Append-Only• Javascript/Erlang• Replication
CouchDB
Wednesday, May 26, 2010
![Page 9: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/9.jpg)
Document Oriented?
• Schema-less• JSON• Attachments
Wednesday, May 26, 2010
![Page 10: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/10.jpg)
JSON DOCUMENT
{ "_id": "foo", "_rev": "1-....", "url": "http://apache.couchdb.org", "vote": 1}
Wednesday, May 26, 2010
![Page 11: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/11.jpg)
FutonWednesday, May 26, 2010
![Page 12: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/12.jpg)
Map/Reduce ?
• Map (M) : Collect a list of values associated to a key
• Return a K-V list• Reduce (R) : Reduce a list of K-V in one
list of values• Rereduce
Wednesday, May 26, 2010
![Page 13: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/13.jpg)
MAP.JS
function(doc) { if (doc.url && doc.vote) emit(doc.url, doc.vote);}
Wednesday, May 26, 2010
![Page 14: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/14.jpg)
{ "total_rows": 3, "offset": 0, "rows": [{ "id": "15c92051cc81d564db4337a05087bc8d", "key": "http://apache.couchdb.org", "value": 1 }, { "id": "fa9658810d25cac893748e4ff15e7253", "key": "http://apache.couchdb.org", "value": 1 }, { "id": "1fa0c68d8455196507b8b01645e65186", "key": "http://mysql.com", "value": -1 }]}
Wednesday, May 26, 2010
![Page 15: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/15.jpg)
REDUCE.JS
function(keys, values, rereduce) { return sum(values);}
{ "rows": [ { "key": "http://mysql.com", "value": -1 }, { "key": "http://apache.couchdb.org", "value": 2 } ]}
Wednesday, May 26, 2010
![Page 16: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/16.jpg)
Réplicatuon
• Incremental• Master-Master• Continue or when needed
Wednesday, May 26, 2010
![Page 17: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/17.jpg)
Wednesday, May 26, 2010
![Page 18: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/18.jpg)
Wednesday, May 26, 2010
![Page 19: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/19.jpg)
Wednesday, May 26, 2010
![Page 20: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/20.jpg)
Wednesday, May 26, 2010
![Page 21: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/21.jpg)
Wednesday, May 26, 2010
![Page 22: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/22.jpg)
Wednesday, May 26, 2010
![Page 23: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/23.jpg)
Wednesday, May 26, 2010
![Page 24: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/24.jpg)
Wednesday, May 26, 2010
![Page 25: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/25.jpg)
More
• Sharding: yes• couchdb-lounge, cloudant, yours• Geocouch. Full r-tree
Wednesday, May 26, 2010
![Page 26: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/26.jpg)
couchdbkit
Wednesday, May 26, 2010
![Page 27: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/27.jpg)
CouchDBKit
• CouchDB Python framework• support CouchDB 0.10.2 & 0.11.0• Simple client• Object Document Mapping (“ODM”)• Django extension• Couchapp compatible
Wednesday, May 26, 2010
![Page 28: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/28.jpg)
client
from couchdbkit import Server
s = Server("http://127.0.0.1:5984")db = s["mydb"]doc = { "a": 1 }db.save_doc(doc)doc["b"] = 2db.save(doc)
doc1 = db.get(doc['_id'])
Wednesday, May 26, 2010
![Page 29: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/29.jpg)
Other features
• db.views• from couchdbkit.loaders import
FileSystemDocsLoader
Wednesday, May 26, 2010
![Page 30: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/30.jpg)
from couchdbkit.loaders import FileSystemDocsLoader
loader = FileSystemDocsLoader('/path/to/example/_design')loader.sync(db, verbose=True)
Wednesday, May 26, 2010
![Page 31: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/31.jpg)
Object Document Mapping
from couchdbkit.schema import *
class MyDoc(Document): a = IntegerProperty() contain(db, MyDoc)
doc = MyDoc()doc.a = 1doc.save()
doc.b = 2doc.save()
doc1 = MyDoc.get(doc._id)
Wednesday, May 26, 2010
![Page 32: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/32.jpg)
Django Extension
• from couchdbkt.ext.django import *• Django helper• manage.py syncdb• DocumentForm
Wednesday, May 26, 2010
![Page 33: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/33.jpg)
settings.py
...
COUCHDB_DATABASES = ( ('djangoapp.greeting', 'http://127.0.0.1:5984/greeting'), )
...
INSTALLED_APPS = ( ... 'couchdbkit.ext.django', 'djangoapp.greeting', ... )
Wednesday, May 26, 2010
![Page 34: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/34.jpg)
models.py
from datetime import datetimefrom couchdbkit.ext.django.schema import *
class Greeting(Document): author = StringProperty() content = StringProperty(required=True) date = DateTimeProperty(default=datetime.utcnow)
Wednesday, May 26, 2010
![Page 35: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/35.jpg)
forms.py
class GreetingForm(DocumentForm): class Meta: document = Greeting
Wednesday, May 26, 2010
![Page 36: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/36.jpg)
views.py
def home(request): greet = None if request.POST: form = GreetingForm(request.POST) if form.is_valid(): greet = form.save() else: form = GreetingForm() greetings = Greeting.view("greeting/all") return render("home.html", { "form": form, "greet": greet, "greetings": greetings }, context_instance=RequestContext(request))
Wednesday, May 26, 2010
![Page 37: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/37.jpg)
0.5
• New mapping (Objects with annotations)
• Admin integration• Possibility to attach design doc to some
objects• MultiDB & DB backend in extension• Eventlet support
Wednesday, May 26, 2010
![Page 38: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/38.jpg)
Wednesday, May 26, 2010
![Page 39: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/39.jpg)
Liens
• http://apache.couchdb.org• http://couchdbkit.org
Wednesday, May 26, 2010
![Page 40: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/40.jpg)
Questions
Wednesday, May 26, 2010
![Page 41: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/41.jpg)
@benoitc
Wednesday, May 26, 2010
![Page 42: Relax your project with CouchDB](https://reader031.vdocuments.net/reader031/viewer/2022020716/546b2752b4af9f000e8b4639/html5/thumbnails/42.jpg)
Cette création est mise à disposition selon le Contrat Paternité 2.0 France disponible en ligne http://
creativecommons.org/licenses/by/2.0/fr/ ou par courrier postal à Creative Commons, 171 Second Street, Suite
300, San Francisco, California 94105, USA.
Wednesday, May 26, 2010