/** * Fetch an object from the datastore by key. Optionally indicate transaction. * @param $key * @param $txn */ private static function fetch_by_key($key, $txn = null) { $lookup_req = new Google_Service_Datastore_LookupRequest(); $lookup_req->setKeys([$key]); if ($txn) { // syslog(LOG_DEBUG, "fetching in transactional context $txn"); $ros = new Google_Service_Datastore_ReadOptions(); $ros->setTransaction($txn); $lookup_req->setReadOptions($ros); } $response = DatastoreService::getInstance()->lookup($lookup_req); $found = $response->getFound(); $extracted = static::extractQueryResults($found); return $extracted; }
/** * @param Google_Service_Datastore_Key|Google_Service_Datastore_Key[] $key_or_keys * @param \Google_Service_Datastore_ReadOptions|ReadOptions\Builder $readOptions * @param array $options * @return Lookup\Results */ public function lookup($key_or_keys, $readOptions = null, $options = []) { if (!is_string($key_or_keys)) { $key_or_keys = [$key_or_keys]; } $request = new Google_Service_Datastore_LookupRequest(); $request->setKeys($key_or_keys); if ($readOptions !== null) { if ($readOptions instanceof ReadOptions\Builder) { $readOptions = $readOptions->build(); } $request->setReadOptions($readOptions->build()); } $response = $this->datastoreService->datasets->lookup($this->datasetId, $request, $options); return new Lookup\Results($response); }