Professional Documents
Culture Documents
with CouchDB
Benoît Chesneau
26/05/2010 - djangocon berlin
Wednesday, May 26, 2010
• Why using a “NoSQL” solution ?
• CouchDB ?
• CouchDB developer
• Maintainer of CouchDBkit,
Couchbeam, Couchapp ,
couchdbproxy, ...
• benoitc@apache.org
Item Item
• Schema-less
• JSON
• Attachments
{
"_id": "foo",
"_rev": "1-....",
"url": "http://apache.couchdb.org",
"vote": 1
}
function(doc) {
if (doc.url && doc.vote)
emit(doc.url, doc.vote);
}
{
"rows": [
{
"key": "http://mysql.com",
"value": -1
},
{
"key": "http://apache.couchdb.org",
"value": 2
}
]
}
Wednesday, May 26, 2010
Réplicatuon
• Incremental
• Master-Master
• Continue or when needed
• Sharding: yes
• couchdb-lounge, cloudant, yours
• Geocouch. Full r-tree
from couchdbkit
import Server
s = Server("http://127.0.0.1:5984")
db = s["mydb"]
doc = { "a": 1 }
db.save_doc(doc)
doc["b"] = 2
db.save(doc)
doc1 = db.get(doc['_id'])
• db.views
• from couchdbkit.loaders import
FileSystemDocsLoader
loader = FileSystemDocsLoader('/path/to/example/_design')
loader.sync(db, verbose=True)
class MyDoc(Document):
a = IntegerProperty()
contain(db, MyDoc)
doc = MyDoc()
doc.a = 1
doc.save()
doc.b = 2
doc.save()
doc1 = MyDoc.get(doc._id)
COUCHDB_DATABASES = (
('djangoapp.greeting', 'http://127.0.0.1:5984/greeting'),
)
...
INSTALLED_APPS = (
...
'couchdbkit.ext.django',
'djangoapp.greeting',
...
)
from datetime
import datetime
from couchdbkit.ext.django.schema import *
class Greeting(Document):
author = StringProperty()
content = StringProperty(required=True)
date = DateTimeProperty(default=datetime.utcnow)
class GreetingForm(DocumentForm):
class Meta:
document = Greeting
• http://apache.couchdb.org
• http://couchdbkit.org