surrealdb / surrealdb.php
官方SurrealDB PHP驱动程序
1.0.0-beta.1
2024-05-13 19:48 UTC
Requires
- php: >=8.2
- ext-curl: *
- brick/math: ^0.11.0
- khill/php-duration: ^1.1
- phrity/websocket: 2.2.2
- ramsey/uuid: 4.7.6
- welpie21/cbor.php: 1.0.1
Requires (Dev)
- nikic/php-parser: v4.19.1
- phpstan/extension-installer: 1.3.1
- phpstan/phpstan: 1.10.67
- phpstan/phpstan-beberlei-assert: 1.1.2
- phpunit/php-code-coverage: 10.1.14
- phpunit/phpunit: 10.5.19
- vimeo/psalm: 5.23.1
This package is auto-updated.
Last update: 2024-09-20 21:13:08 UTC
README
官方SurrealDB SDK for PHP。
surrealdb.php
官方SurrealDB SDK for PHP。
文档
查看SDK文档 这里。
如何安装
您可以通过 Composer 安装SurrealDB SDK。如果您尚未安装Composer,您可以 从这里 下载。
composer require surrealdb/surrealdb.php
入门指南
要开始,您需要创建SurrealDB HTTP或WebSocket类的实例。
// Make a new instance of the SurrealDB class. Use the ws or wss protocol for having WebSocket functionality. $db = new \Surreal\Surreal(); $db->connect("https://:8000", [ "namespace" => "test", "database" => "test" ]);
基本查询
在PHP SDK中,我们有一个简单的API,允许您与SurrealDB交互。以下示例展示了如何与数据库交互。
以下示例需要SurrealDB已 安装 并在8000端口运行。
// Connect set the specified namespace and database. $db = new \Surreal\Surreal(); $db->connect("https://:8000", [ "namespace" => "test", "database" => "test" ]); // We want to authenticate as a root user. $token = $db->signin([ "user" => "root", "pass" => "root" ]); // Create a new person in the database with a custom id. $person = $db->create("person", [ "title" => "Founder & CEO", "name" => [ "first" => "Tobie", "last" => "Morgan Hitchcock" ], "marketing" => true ]); // Get the person with the name "John Doe". $record = \Surreal\Cbor\Types\RecordId::create("person", "john"); $person = $db->select($record); // Update a person record with a specific id $record = \Surreal\Cbor\Types\RecordId::create("person", "john"); $person = $db->merge($record, ["age" => 31]); // Select all people records. $people = $db->select("person"); // Perform a custom advanced query. $groups = $db->query('SELECT marketing, count() FROM $tb GROUP BY marketing', [ "tb" => \Surreal\Cbor\Types\Table::create("person") ]); // Close the connection between the application and the database. $db->disconnect();
贡献
要求
- PHP 8.1或更高版本
- Composer
- SurrealDB 1.4.0或更高版本
运行测试
./vendor/bin/phpunit -c phpunit.xml
目录结构
src
- 库的源代码tests
- 库的单元测试