예제 #1
0
 /**
  * @return \Google_Service_Datastore_Query
  */
 public function build()
 {
     $query = new \Google_Service_Datastore_Query();
     if (!empty($this->projections)) {
         $query->setProjection($this->projections);
     }
     if (!empty($this->kinds)) {
         $query->setKinds($this->kinds);
     }
     if (!is_null($this->filter)) {
         $query->setFilter($this->filter);
     }
     if (!empty($this->orders)) {
         $query->setOrder($this->orders);
     }
     if (!empty($this->groupBys)) {
         $query->setGroupBy($this->groupBys);
     }
     if (!is_null($this->startCursor)) {
         $query->setStartCursor($this->startCursor);
     }
     if (!is_null($this->endCursor)) {
         $query->setEndCursor($this->endCursor);
     }
     if (!is_null($this->offset)) {
         $query->setOffset($this->offset);
     }
     if (!is_null($this->limit)) {
         $query->setLimit($this->limit);
     }
     return $query;
 }
 public function listBooks($limit = 10, $cursor = null)
 {
     $query = new \Google_Service_Datastore_Query();
     $query->setKinds(['Book']);
     $query->setOrder('title');
     $query->setLimit($limit);
     $query->setStartCursor($cursor);
     $request = new \Google_Service_Datastore_RunQueryRequest();
     $request->setQuery($query);
     $response = $this->datastore->datasets->runQuery($this->datasetId, $request);
     /** @var \Google_Service_Datastore_QueryResultBatch $batch */
     $batch = $response->getBatch();
     return array('books' => $response, 'next_page_token' => $batch->getEndCursor());
 }