savander/surrealdb-client

The client for SurrealDB database.

dev-main 2022-10-03 18:22 UTC

This package is auto-updated.

Last update: 2024-12-04 15:37:31 UTC


README

⚠️ Warning!

The package is in the very early stages of development!


The client allows you to connect to SurrealDB and perform queries.

Installation

You can install the package via composer:

composer require savander/surrealdb-client

Usage

// The connection options.
$connectionOptions = (new ConnectionOptions())
    ->setNamespace('test')
    ->setDatabase('test')
    ->setUsername(getenv('DB_USER'))
    ->setPassword(getenv('DB_PASS'));

// The persistent connection to the SurrealDB Websocket server.
$connection = new Connection($connectionOptions);

// The results of the query. It returns the Johnny :)
$createdJohnny = $connection
    ->raw("CREATE author SET name.first = 'Johnny'")
    ->results();

// The results of the selection query, it returns the previously created Johnny.
//  > Please note that, we used `prepare` method here. It's much safer to do this that way.
//  > In this case, we are sending attributes as a separate array of arguments.
//  > You could use that method in previous step as well.
$selectedJohnny = $connection
    ->prepare('SELECT * FROM $author', ['author' => $createdJohnny['id']])
    ->results();

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.