Your SlideShare is downloading. ×
0
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Couchdbkit & Dango
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Couchdbkit & Dango

2,626

Published on

presentation about the use of couchdbkit in django at @djangocong

presentation about the use of couchdbkit in django at @djangocong

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,626
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
30
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. CouchDB & Django avec CouchDBkit Benoît Chesneau 25/04/2010 - djangocong Sunday, April 25, 2010
  • 2. benoît chesneau benoitc@apache.org Artisan web Minimal web & Opensource Enki Multimedia http://www.e-engura.com Sunday, April 25, 2010
  • 3. • Pourquoi utiliser une solution “NoSQL” ? • CouchDB • CouchDBKit: CouchDB & Django Sunday, April 25, 2010
  • 4. Pourquoi ? • On a pas forcement besoin de “scalabilité” • Maj des bases de données < 300 Go (2 Go) • Souvent les requêtes sont rapides • Tout tient sur une machine Sunday, April 25, 2010
  • 5. Souplesse • Differents types de contenu • Supprimer les “content-types” • Faire de la dénormalisation simplement • Gérer la migration de données/schema facilement Sunday, April 25, 2010
  • 6. Garder ses données Sunday, April 25, 2010
  • 7. Ex: boutique en ligne Données Commande Livraison clients Item Item Sunday, April 25, 2010
  • 8. • Gérer des differents produits • Sauver une commande avec le détail des produits • à un instant T (le produit est figé) • Ne pas perdre la commande • Ne pas perdre les infos de livraisons et clients Sunday, April 25, 2010
  • 9. CouchDB • Base de données orientées document • REST • Map/Reduce (M/R) • Append-Only • Javascript/Erlang • Réplication Sunday, April 25, 2010
  • 10. Orientée Document? • Pas de schema • JSON • Attachements Sunday, April 25, 2010
  • 11. DOCUMENT JSON { "_id": "foo", "_rev": "1-....", "url": "http://apache.couchdb.org", "vote": 1 } Sunday, April 25, 2010
  • 12. Map/Reduce ? • Map (M) : Collecter une liste de valeurs en fonction d’une clé • Retourne une liste de clés/valeurs (K/V) • Reduce (R) : Réduire une liste de clés/ valeurs en une liste de valeurs • Rereduce Sunday, April 25, 2010
  • 13. MAP.JS function(doc) { if (doc.url && doc.vote) emit(doc.url, doc.vote); } { "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 } Sunday, April 25, 2010
  • 14. REDUCE.JS function(keys, values, rereduce) { return sum(values); } { "rows":[ { "key": "http://mysql.com", json "value": -1 result }, { "key": "http://apache.couchdb.org", "value": 2 } ]} Sunday, April 25, 2010
  • 15. Futon Sunday, April 25, 2010
  • 16. Réplicatuon • Incrémentale • Master-Master • Continue ou à la demande Sunday, April 25, 2010
  • 17. Sunday, April 25, 2010
  • 18. Sunday, April 25, 2010
  • 19. Sunday, April 25, 2010
  • 20. Sunday, April 25, 2010
  • 21. Sunday, April 25, 2010
  • 22. Sunday, April 25, 2010
  • 23. Sunday, April 25, 2010
  • 24. Sunday, April 25, 2010
  • 25. CouchDBKit • CouchDB Python framework • supporte CouchDB 0.10.2 & 0.11.0 • Client simple • Schema • Extension django • Compatible couchapp Sunday, April 25, 2010
  • 26. 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"] = 2 db.save(doc) doc1 = db.get(doc['_id']) Sunday, April 25, 2010
  • 27. Autres fonctions • db.views • from couchdbkit.loaders import FileSystemDocsLoader Sunday, April 25, 2010
  • 28. from couchdbkit.loaders import FileSystemDocsLoader loader = FileSystemDocsLoader('/path/to/example/_design') loader.sync(db, verbose=True) Sunday, April 25, 2010
  • 29. schema from couchdbkit.schema import * 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) Sunday, April 25, 2010
  • 30. Extension Django • from couchdbkt.ext.django import * • Django helper • manage.py syncdb • DocumentForm Sunday, April 25, 2010
  • 31. settings.py ... COUCHDB_DATABASES = ( ('djangoapp.greeting', 'http://127.0.0.1:5984/ greeting'), ) ... INSTALLED_APPS = ( .... 'couchdbkit.ext.django', 'djangoapp.greeting', .... ) Sunday, April 25, 2010
  • 32. models.py from datetime import datetime from couchdbkit.ext.django.schema import * class Greeting(Document): author = StringProperty() content = StringProperty(required=True) date = DateTimeProperty(default=datetime.utcnow) Sunday, April 25, 2010
  • 33. forms.py class GreetingForm(DocumentForm): class Meta: document = Greeting Sunday, April 25, 2010
  • 34. 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)) Sunday, April 25, 2010
  • 35. 0.5 • Nouveau mapper àla sqlalchemy • Intégration de futon dans l’admin • Gestion de design docs ameliorée • Support Eventlet • ... Sunday, April 25, 2010
  • 36. Sunday, April 25, 2010
  • 37. Liens • http://apache.couchdb.org • http://couchdbkit.org Sunday, April 25, 2010
  • 38. Questions Sunday, April 25, 2010
  • 39. @benoitc Sunday, April 25, 2010
  • 40. 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. Sunday, April 25, 2010

×