Lookup records by key
public lookup ( array $keys, array $options = [] ) : array | ||
$keys | array | The identifiers to look up. |
$options | array | [optional] { Configuration Options @type string $readConsistency See [ReadConsistency](https://cloud.google.com/datastore/reference/rest/v1/ReadOptions#ReadConsistency). @type string $transaction The transaction ID, if the query should be run in a transaction. @type string|array $className If a string, the name of the class to return results as. Must be a subclass of {@see \Google\Cloud\Datastore\Entity}. If not set, {@see \Google\Cloud\Datastore\Entity} will be used. If an array is given, it must be an associative array, where the key is a Kind and the value is the name of a subclass of {@see \Google\Cloud\Datastore\Entity}. @type bool $sort If set to true, results in each set will be sorted to match the order given in $keys. **Defaults to** `false`. } |
return | array | Returns an array with keys [`found`, `missing`, and `deferred`]. Members of `found` will be instance of {@see \Google\Cloud\Datastore\Entity}. Members of `missing` and `deferred` will be instance of {@see \Google\Cloud\Datastore\Key}. |
/** * Get multiple entities inside a transaction * * Example: * ``` * $keys = [ * $datastore->key('Person', 'Bob'), * $datastore->key('Person', 'John') * ]; * * $entities = $transaction->lookup($keys); * * foreach ($entities['found'] as $entity) { * echo $entity['firstName']; * } * ``` * * @param Key[] $key The identifiers to look up. * @param array $options [optional] { * Configuration Options * * @type string|array $className If a string, the name of the class to return results as. * Must be a subclass of {@see Google\Cloud\Datastore\Entity}. * If not set, {@see Google\Cloud\Datastore\Entity} will be used. * If an array is given, it must be an associative array, where * the key is a Kind and the value is the name of a subclass of * {@see Google\Cloud\Datastore\Entity}. * } * @return array Returns an array with keys [`found`, `missing`, and `deferred`]. * Members of `found` will be instance of * {@see Google\Cloud\Datastore\Entity}. Members of `missing` and * `deferred` will be instance of {@see Google\Cloud\Datastore\Key}. */ public function lookupBatch(array $keys, array $options = []) { return $this->operation->lookup($keys, $options + ['transaction' => $this->transactionId]); }
/** * Get multiple entities * * To lookup entities inside a transaction, use * {@see Google\Cloud\Datastore\Transaction::lookupBatch()}. * * Example: * ``` * $keys = [ * $datastore->key('Person', 'Bob'), * $datastore->key('Person', 'John') * ]; * * $entities = $datastore->lookupBatch($keys); * * foreach ($entities['found'] as $entity) { * echo $entity['firstName'] . PHP_EOL; * } * ``` * * @param Key[] $key The identifiers to look up. * @param array $options [optional] { * Configuration Options * * @type string $readConsistency See * [ReadConsistency](https://cloud.google.com/datastore/reference/rest/v1/ReadOptions#ReadConsistency). * @type string|array $className If a string, the name of the class to return results as. * Must be a subclass of {@see Google\Cloud\Datastore\Entity}. * If not set, {@see Google\Cloud\Datastore\Entity} will be used. * If an array is given, it must be an associative array, where * the key is a Kind and the value is the name of a subclass of * {@see Google\Cloud\Datastore\Entity}. * @type bool $sort If set to true, results in each set will be sorted * to match the order given in $keys. **Defaults to** `false`. * } * @return array Returns an array with keys [`found`, `missing`, and `deferred`]. * Members of `found` will be instance of * {@see Google\Cloud\Datastore\Entity}. Members of `missing` and * `deferred` will be instance of {@see Google\Cloud\Datastore\Key}. */ public function lookupBatch(array $keys, array $options = []) { return $this->operation->lookup($keys, $options); }