Cloud Datastore Client - Class Entity (1.30.0)
Stay organized with collections
Save and categorize content based on your preferences.
Version 1.30.0 keyboard_arrow_down
Reference documentation and code samples for the Cloud Datastore Client class Entity.
A Datastore Entity
Entity implements PHP's ArrayAccess , allowing
access via the array syntax (example below).
Properties are mapped automatically to their corresponding Datastore value
types. Refer to the table below for a guide to how types are stored.
Example:
use Google\Cloud\Datastore\DatastoreClient;
$datastore = new DatastoreClient();
$key = $datastore->key('Person', 'Bob');
$entity = $datastore->entity($key, [
'firstName' => 'Bob',
'lastName' => 'Testguy'
]);
$firstName = $entity['firstName']; // 'Bob'
$entity['location'] = 'Detroit, MI';
// Custom entity types can be created by implementing the datastore entity interface.
// You can also define mappings to correctly fetch embedded entities.
use Google\Cloud\Datastore\EntityTrait;
use Google\Cloud\Datastore\EntityInterface;
class Business implements EntityInterface
{
use EntityTrait;
public static function mappings()
{
return [
'parent' => Business::class
];
}
}
$alphabet = new Business;
$alphabet->set([
'companyName' => 'Alphabet'
]);
$key = $datastore->key('Business', 'Google');
$google = $datastore->entity($key, [
'companyName' => 'Google',
'parent' => $alphabet
], [
'className' => Business::class
]);
$datastore->insert($google);
$google = $datastore->lookup($key, ['className' => Business::class]);
echo get_class($google); // `Business`
echo get_class($google->get()['parent']); // `Business`
Namespace
Google \ Cloud \ Datastore
Methods
offsetSet
Parameters
Name
Description
key
string
The value name.
val
mixed
The value.
Returns
Type
Description
void
offsetExists
Parameter
Name
Description
key
string
the value to check.
Returns
Type
Description
bool
offsetUnset
Parameter
Name
Description
key
string
the value to remove.
Returns
Type
Description
void
offsetGet
Parameter
Name
Description
key
string
the value to retrieve.
Returns
Type
Description
mixed
__get
Parameter
Name
Description
property
string
Returns
Type
Description
mixed
__set
Parameters
Name
Description
property
string
value
mixed
Returns
Type
Description
void
__unset
Parameter
Name
Description
property
string
Returns
Type
Description
void
__isset
Parameter
Name
Description
property
string
Returns
Type
Description
bool
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License , and code samples are licensed under the Apache 2.0 License . For details, see the Google Developers Site Policies . Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-11-19 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-11-19 UTC."],[],[]]