• Start

v1 (stable)

/

Methods

patch

The ->patch() method for the SurrealDB SDK for PHP applies JSON patch changes to records in the database.

Applies JSON Patch changes to all records, or a specific record, in the database.

Method Syntax
$db->patch($thing, $data, $diff)
Note

This function patches the current document / record data with the specified JSON Patch data.

Arguments

Type

Description

thingstring

,

RecordId

or

StringRecordId

The table name or the specific RecordId to patch.

dataassociative array

The JSON Patch data with which to patch the records.

diffboolean

Whether to return the diff of the patched record.

// Update all records in a table
$people = $db->patch('person', [
		[ "op" => 'replace', "path" => '/created_at',
	    "value" => new Date() ],
]);

// Update a record with a specific ID
$person = $db->patch(new RecordId('person', 'tobie'), [
		[ "op" => 'replace', "path" => '/settings/active',
	    "value" => false ],
		[ "op" => 'add', "path" => '/tags', "value" => ['developer',
	    'engineer'] ],
	[ "op" => 'remove', "path" => '/temp' ],
]);

This function will run the following query in the database.

UPDATE $thing PATCH $data;

Was this page helpful?