doctrine/couchdb
最新稳定版本:2.0.0-alpha1
Composer 安装命令:
composer require doctrine/couchdb
包简介
CouchDB Client
关键字:
README 文档
README
Simple API that wraps around CouchDBs v2.x HTTP API.
For CouchDB 1.x, please check our release/1.0.0 branch.
Features
- Create, Delete, List Databases
- Create, Update, Delete Documents
- Bulk API for Creating/Updating Documents
- Find Documents by ID
- Generate UUIDs
- Design Documents
- Query
_all_docsview - Query Changes Feed
- Query Views
- Compaction Info and Triggering APIs
- Replication API
- Symfony Console Commands
- Find Documents using Mango Query
Installation
With Composer:
{
"require": {
"doctrine/couchdb": "@dev"
}
}
Usage
Basic Operations
Covering the basic CRUD Operations for databases and documents:
<?php $client = \Doctrine\CouchDB\CouchDBClient::create(array('dbname' => 'doctrine_example')); // Create a database. $client->createDatabase($client->getDatabase()); // Create a new document. list($id, $rev) = $client->postDocument(array('foo' => 'bar')); // Update a existing document. This will increment the revision. list($id, $rev) = $client->putDocument(array('foo' => 'baz'), $id, $rev); // Fetch single document by id. $doc = $client->findDocument($id); // Fetch multiple documents at once. $docs = $client->findDocuments(array($id)); // Return all documents from database (_all_docs?include_docs=true). $allDocs = $client->allDocs(); // Delete a single document. $client->deleteDocument($id, $rev); // Delete a database. $client->deleteDatabase($client->getDatabase()); //Search documents using Mango Query CouchDB v2.x $selector = ['_id'=>['$gt'=>null]]; $options = ['limit'=>1,'skip'=>1,'use_index'=>['_design/doc','index'],'sort'=>[['_id'=>'desc']]]; $query = new \Doctrine\CouchDB\Mango\MangoQuery($selector,$options); $docs = $client->find($query); $query = new \Doctrine\CouchDB\Mango\MangoQuery(); $query->select(['_id', 'name'])->where(['$and'=> [ [ 'name'=> [ '$eq'=> 'Under the Dome', ], 'genres'=> [ '$in'=> ['Drama','Comedy'], ], ], ])->sort([['_id'=>'desc']])->limit(1)->skip(1)->use_index(['_design/doc','index']); $docs = $client->find($query);
Views
A simple example demonstrating how to create views and query them:
<?php class ArticlesDesignDocument implements \Doctrine\CouchDB\View\DesignDocument { public function getData() { return array( 'language' => 'javascript', 'views' => array( 'by_author' => array( 'map' => 'function(doc) { if(\'article\' == doc.type) { emit(doc.author, doc._id); } }', 'reduce' => '_count' ), ), ); } } $client->createDesignDocument('articles', new ArticlesDesignDocument()); // Fill database with some data. foreach (array('Alice', 'Bob', 'Bob') as $author) { $client->postDocument(array( 'type' => 'article', 'author' => $author, 'content' => 'Lorem ipsum' )); } // Query all articles. $query = $client->createViewQuery('articles', 'by_author'); $query->setReduce(false); $query->setIncludeDocs(true); $result = $query->execute(); foreach ($result as $row) { $doc = $row['doc']; echo 'Article by ', $doc['author'], ': ', $doc['content'], "\n"; } // Article by Alice: Lorem ipsum // Article by Bob: Lorem ipsum // Article by Bob: Lorem ipsum // Query all articles written by bob. $query = $client->createViewQuery('articles', 'by_author'); $query->setKey('Bob'); // ... // Query the _count of articles each author has written. $query = $client->createViewQuery('articles', 'by_author'); $query->setReduce(true); $query->setGroupLevel(1); // group_level=1 means grouping by author. $result = $query->execute(); foreach ($result as $row) { echo 'Author ', $row['key'], ' has written ', $row['value'], ' articles', "\n"; } // Author Alice has written 1 articles // Author Bob has written 2 articles
doctrine/couchdb 适用场景与选型建议
doctrine/couchdb 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.04M 次下载、GitHub Stars 达 122, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「persistence」 「couchdb」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 doctrine/couchdb 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 doctrine/couchdb 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 doctrine/couchdb 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This bundle provides tools to build persistence-agnostic storage layer.
The DreamFactory(tm) CouchDB Service.
Propel2 is an open-source Object-Relational Mapping (ORM) for PHP 5.5 and up.
Kinikit - PHP Application development framework MVC component
Doctrine2 managers builder
CouchDB adapter for Daikon-CQRS projects.
统计信息
- 总下载量: 1.04M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 126
- 点击次数: 30
- 依赖项目数: 48
- 推荐数: 25
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-04