/** * 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]); }
/** * @param string $propertyName * @return \Google_Service_Datastore_PropertyReference */ public static function newPropertyReference($propertyName) { $property = new \Google_Service_Datastore_PropertyReference(); $property->setName($propertyName); return $property; }