GitXplorerGitXplorer
s

surrealdb.php

public
40 stars
7 forks
2 issues

Commits

List of commits on branch main.
Verified
d4c94c771dd279d4e2d651e2d3bfc7c84d5be133

SDK improvements and changes (#10)

wwelpie21 committed 2 months ago
Verified
4823aa5abc67a1659f76dbaa21e27b8f1b86e0fd

Update README.md (#9)

kkearfy committed 4 months ago
Unverified
88a6081a9f41caa192722002e822fb43ed0ab745

Update README

ttobiemh committed 4 months ago
Verified
ecaf6aae4dfd7ab91e6055d258ec2c4a60f622b6

Update composer.json (#8)

kkearfy committed 4 months ago
Verified
d173526a80e45c0402e16b98c14b8bd472e9cf98

Refactor and modernize the PHP SDK (#7)

wwelpie21 committed 4 months ago
Verified
458d895f7670af86f1a3b05a41327bd968c57fae

Add tls (#4)

mmcprog1 committed a year ago

README

The README file for this repository.

 

The official SurrealDB SDK for PHP.


     

     

surrealdb.php

The official SurrealDB SDK for PHP.

Documentation

View the SDK documentation here.

How to install

You install the SurrealDB SDK via Composer. If you don't have Composer installed, you can download it here.

composer require surrealdb/surrealdb.php

Getting started

To get started, you need to create a new instance of the SurrealDB HTTP or WebSocket Class.

// Make a new instance of the SurrealDB class. Use the ws or wss protocol for having WebSocket functionality.
$db = new \Surreal\Surreal();

$db->connect("http://localhost:8000", [
    "namespace" => "test",
    "database" => "test"
]);

Basic Querying

In the PHP SDK, We have a simple API that allows you to interact with SurrealDB. The following example shows how to interact with the database.

The example below requires SurrealDB to be installed and running on port 8000.

// Connect set the specified namespace and database.
$db = new \Surreal\Surreal();

$db->connect("http://localhost: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();

Contributing

Requirements

  • PHP 8.1 or higher
  • Composer
  • SurrealDB 1.4.0 or higher

Run tests

./vendor/bin/phpunit -c phpunit.xml

Directory Structure

  • src - The source code of the library
  • tests - The unit tests of the library