Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.