/**
  * Creates a query object for pulling the last $limit number of
  * "PubSubMessage" items, equivalent to the following GQL:
  *
  *    SELECT * from DatastoreComment ORDER BY created DESC LIMIT 20
  *
  * @see https://cloud.google.com/datastore/docs/concepts/gql
  */
 public function createSimpleQuery($limit = 20)
 {
     $request = new \Google_Service_Datastore_RunQueryRequest();
     $query = new \Google_Service_Datastore_Query();
     $order = new \Google_Service_Datastore_PropertyOrder();
     $order->setDirection('descending');
     $property = new \Google_Service_Datastore_PropertyReference();
     $property->setName('created');
     $order->setProperty($property);
     $query->setOrder([$order]);
     $kind = new \Google_Service_Datastore_KindExpression();
     $kind->setName(self::KIND);
     $query->setKinds([$kind]);
     $query->setLimit($limit);
     $request->setQuery($query);
     return $request;
 }
 /**
  * @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());
 }
 /**
  * Create a query object for the given Kind.
  */
 protected static function createQuery($kind_name)
 {
     $query = new Google_Service_Datastore_Query();
     $kind = new Google_Service_Datastore_KindExpression();
     $kind->setName($kind_name);
     $query->setKinds([$kind]);
     return $query;
 }