Skip to content

Instantly share code, notes, and snippets.

@Natim
Created June 7, 2012 12:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Natim/2888668 to your computer and use it in GitHub Desktop.
Save Natim/2888668 to your computer and use it in GitHub Desktop.
Getting started with CouchdbKit
greetings/
├── _design
│   └── greetings
│   └── views
│   └── all
│   └── map.js
└── greetings.py
4 directories, 2 files
# -*- coding: utf-8 -*-
from couchdbkit.loaders import FileSystemDocsLoader
import os
import datetime
from couchdbkit import *
class Greeting(Document):
author = StringProperty()
content = StringProperty()
date = DateTimeProperty()
# server object
server = Server()
# create database
db = server.get_or_create_db("greeting")
# associate Greeting to the db
Greeting.set_db(db)
# create a new greet
greet = Greeting(
author=u"Rémy",
content="Welcome to couchdbkit world",
date=datetime.datetime.utcnow()
)
# save it
greet.save()
loader = FileSystemDocsLoader('_design')
loader.sync(db, verbose=True)
toto = list(Greeting.view('greetings/all'))
print toto
function(doc) {
if (doc.doc_type == "Greeting")
emit(doc._id, doc);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment