barrel-db / barrel-php
Barrel-DB的PHP客户端库,Barrel-DB是一个面向文档的数据库。
dev-master
2018-03-13 16:27 UTC
Requires
- php: >=5.5
- guzzlehttp/guzzle: ^6.3
Requires (Dev)
- phpunit/phpunit: ^4.0
This package is not auto-updated.
Last update: 2024-09-23 06:59:28 UTC
README
Barrel-DB的PHP客户端,Barrel-DB是一个开源的面向文档的数据库,注重数据局部性(将数据放在你附近)和P2P。
访问https://barrel-db.org/以获取Barrel-DB的安装说明,并了解Barrel-DB的基础概念。
安装
通过composer安装
$ composer require barrel-db/barrel-php
用法
Barrel-DB使用JSON格式,但使用此库可以让你通过使用PHP原生的关联数组来避免将数据转换为JSON。例如:
以下文档
{
"id" : "tahteche",
"name" : "Teche Tah",
"hobbies" : ["eat", "sleep", "code"]
}
将被
[ "id" => "tahteche", "name" => "Teche Tah", "hobbies" => ["eat", "sleep", "code"] ]
以下示例假设你的Barrel-DB服务器正在https://:7080/dbs/上提供服务,而你正在进行的数据库操作是testdb。以下所有函数都在一个Database类实例上操作,该实例使用服务器链接和数据库名称创建。
<?php use Barrel\Database; $server_url = 'https://:7080/dbs'; $db_name = 'testdb'; ======================================================= Database Operations - Create, get, and delete databases ======================================================= //Create instance of the Database class which you will use for request to create or use a Barrel databse. $db = new Database($server_url, $db_name); //Create 'testdb' database on you Barrel server $res = $db->post(); //Get info about the 'testdb' database e.g number of documents $res = $db->get(); //Get list of all databases available on your Barrel server $res = $db->getAll(); //Delete 'testdb' database from Barrel $res = $db->delete(); =============================================================== Document Operations - Create, read, update and delete documents =============================================================== //Create a document in the 'testdb' database $res = $db->postDoc($doc); //Read a document from the 'testdb' database $res = $db->getDoc($doc_id); //Read ALL documents from the 'testdb' database $res = $db->postAllDocs(); //Update a document in the 'testdb' database $res = $db->putDoc($doc); //Delete a document from the 'testdb' database $res = $db->deleteDoc($doc_id);
提交错误和功能请求
错误和功能请求通过GitHub问题跟踪。
作者
Tah Teche - https://twitter.com/tahteche
许可证
Barrel-php采用Apache-2.0许可证 - 有关详细信息,请参阅LICENSE文件