/**
  * 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;
 }
 /**
  * Create a property 'order' and add it to a datastore query
  * @param $query the datastore query object
  * @param $name property name
  * @param $direction sort direction
  */
 protected static function addOrder($query, $name, $direction = 'descending')
 {
     $order = new Google_Service_Datastore_PropertyOrder();
     $property_ref = new Google_Service_Datastore_PropertyReference();
     $property_ref->setName($name);
     $order->setProperty($property_ref);
     $order->setDirection($direction);
     $query->setOrder([$order]);
 }
Ejemplo n.º 3
0
 /**
  * @param string $propertyName
  * @param Direction|string $direction
  * @return Google_Service_Datastore_PropertyReference
  */
 public static function newPropertyOrder($propertyName, $direction = 'ASCENDING')
 {
     $order = new \Google_Service_Datastore_PropertyOrder();
     $order->setProperty(\DatastoreHelper::newPropertyReference($propertyName));
     $order->setDirection(Direction::get($direction)->value());
     return $order;
 }