使用PHP-ON-COUCH,我尝试使用php-on-couch获取couchdb中的所有记录,但它不能快速运行。
require_once "lib/couch.php";
require_once "lib/couchClient.php";
require_once "lib/couchDocument.php";
$couch_dsn = "http://localhost:5984/";
$couch_db = "couch";
$client = new couchClient($couch_dsn,$couch_db);
$all_singers = $client->getAllDocs();
foreach ( $all_singers->rows as $row ) {
$doc = $client->getDoc($id);
echo $doc->singer;
echo $doc->title;
echo $doc->description;
}
还有其他方法可以做到这一点吗?
提前谢谢
答案 0 :(得分:0)
您没有正确使用这些功能。你现在正在做的事情非常慢,因为你获取了所有的文档,然后你用(getDoc)函数逐一获取它们。当您查询所有文档时,您会得到以下内容:
class A(object):
def __call__(self, desc, obj, cls):
print 'A::__call__\n'
class B(object):
__get__ = A()
class C(object):
def __get__(self, obj, cls):
print 'C::__get__\n'
class D(object):
attr = B()
class E(object):
attr = C()
>>> D().attr
A::__call__
>>> E().attr
C::__get__
以下是您的代码的修订版本:
{
"total_rows": 0,
"count": 0,
"rows": [{
"key": 1,
"value": "value",
"doc": {
"singer": "Foo",
"title": "bar"
}
}]
}