f2h2h1 / couchdb-client
a simple couchdb client base on php
0.0.1
2020-06-09 13:19 UTC
Requires
- symfony/http-client: 5.1
Requires (Dev)
This package is auto-updated.
Last update: 2024-11-09 22:50:01 UTC
README
快速开始
安装 couchdb
docker run -p 5984:5984 -e COUCHDB_USER=admin -e COUCHDB_PASSWORD=password --name couchdb -d couchdb:3.1
声明依赖
composer require f2h2h1/couchdb-client
使用例子
use F2h2h1\CouchDB\SimpleClinet; require_once(__DIR__ . '/../vendor/autoload.php'); $dbname = 'test_' . substr(md5(uniqid(microtime(true), true)), 0, mt_rand(3, 6)); $config = [ 'address' => 'http://127.0.0.1:5984', 'user' => 'admin', 'password' => 'password', 'dbname' => $dbname, ]; $client = new SimpleClinet($config); $client->deleteDatabase(); $client->createDatabase(); echo 'create database success' . PHP_EOL; $data = ['name' => 'tony', 'age' => 23]; list($id, $rev) = $client->postDocument($data); var_dump($id, $rev); $docs = $client->findDocument($id); var_dump($docs); $data['age'] = 24; list($id, $rev) = $client->putDocument($data, $id, $rev); var_dump($id, $rev); $docs = $client->findDocument($id); var_dump($docs); $client->deleteDocument($id, $rev); echo 'delete document success' . PHP_EOL; $client->deleteDatabase(); echo 'delete database success' . PHP_EOL;
开发
克隆仓库
git clone https://github.com/f2h2h1/orm.git
运行 composer
composer install
运行测试用例
composer exec -v phpunit tests/CouchDBClientTest.php