Esempio n. 1
0
        doc = {'payload': payload}
        self.db.save(doc)


class Create(Root):
    def render_GET(self, request):
        # blocking
        self.insert_doc()
        return "created:ok\n"

class Delete(Root):
    def render_GET(self, request):
        # blocking
        _couch.delete_db()
        return "deleted:ok\n"

class Count(Root):
    def render_GET(self, request):
        count = db.info()['doc_count']
        return "%s docs\n" % count

db = _couch.get_db()
Root.db = db

root = Create()
root.putChild('delete', Delete())
root.putChild('count', Count())
site = server.Site(root)
reactor.listenTCP(8080, site)
reactor.run()
Esempio n. 2
0
def setup_db():
    global db
    db = _couch.get_db()
Esempio n. 3
0
        _couch.delete_db()
        return "deleted:ok\n"

class Count(Root):
    @defer.inlineCallbacks
    def _get_count(self):
        info = yield db.infoDB('couch-benchmarks')
        count =  info['doc_count']
        defer.returnValue("%s docs\n" % count)
    
    def render_GET(self, request):
        d = self._get_count()
        d.addCallback(self._write_GET, request)
        return server.NOT_DONE_YET

db_sync = _couch.get_db()
db = CouchDB('localhost')
Root.db = db
Root.db_sync = db_sync

def create_db():
    d = db.createDB('couch-benchmarks')

    def del_and_create(_):
        d = db.deleteDB('couch-benchmarks')
        d.addCallback(lambda _: db.createDB('couch-benchmarks'))
        return d
    d.addErrback(del_and_create)
    d.addErrback(lambda f: log.err(f))

reactor.callWhenRunning(create_db)