Created
June 7, 2012 12:54
-
-
Save Natim/2888668 to your computer and use it in GitHub Desktop.
Getting started with CouchdbKit
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
greetings/ | |
├── _design | |
│ └── greetings | |
│ └── views | |
│ └── all | |
│ └── map.js | |
└── greetings.py | |
4 directories, 2 files |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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