Cloud Datastore Client - Class Entity (1.28.2)
Stay organized with collections
Save and categorize content based on your preferences.
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-08-09 UTC.
[{
"type": "thumb-down",
"id": "hardToUnderstand",
"label":"Hard to understand"
},{
"type": "thumb-down",
"id": "incorrectInformationOrSampleCode",
"label":"Incorrect information or sample code"
},{
"type": "thumb-down",
"id": "missingTheInformationSamplesINeed",
"label":"Missing the information/samples I need"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]
{
"last_modified": "Last updated 2024-08-09 UTC.",
"state": ""
}