Example #1
0
def make_kind_stats_query(namespace, kind, latest_timestamp):
  """Make a Query to fetch the latest kind statistics."""
  kind_stat_query = query_pb2.Query()
  if namespace is None:
    kind_stat_query.kind.add().name = '__Stat_Kind__'
  else:
    kind_stat_query.kind.add().name = '__Stat_Ns_Kind__'

  kind_filter = datastore_helper.set_property_filter(
      query_pb2.Filter(), 'kind_name', PropertyFilter.EQUAL, unicode(kind))
  timestamp_filter = datastore_helper.set_property_filter(
      query_pb2.Filter(), 'timestamp', PropertyFilter.EQUAL,
      latest_timestamp)

  datastore_helper.set_composite_filter(kind_stat_query.filter,
                                        CompositeFilter.AND, kind_filter,
                                        timestamp_filter)
  return kind_stat_query
Example #2
0
    def query(self):
        # Instantiate a filter protobuf
        # You MUST instantiate the filter before the query, then instantiate
        # the query with the filter.
        filter_pb = query_pb2.Filter()

        # Get all non-deleted model instances
        helper.set_property_filter(filter_pb, 'deleted',
                                   query_pb2.PropertyFilter.EQUAL, False)

        # Instantiate a query protobuf
        query_pb = query_pb2.Query(filter=filter_pb)
        helper.set_kind(query_pb, self.model)

        return query_pb