예제 #1
0
    def _to_protobuf(self):
        """Convert the current query into the equivalent protobuf.

        Returns:
            google.cloud.firestore_v1.types.StructuredQuery: The
            query protobuf.
        """
        projection = self._normalize_projection(self._projection)
        orders = self._normalize_orders()
        start_at = self._normalize_cursor(self._start_at, orders)
        end_at = self._normalize_cursor(self._end_at, orders)

        query_kwargs = {
            "select":
            projection,
            "from": [
                query_pb2.StructuredQuery.CollectionSelector(
                    collection_id=self._parent.id,
                    all_descendants=self._all_descendants)
            ],
            "where":
            self._filters_pb(),
            "order_by":
            orders,
            "start_at":
            _cursor_pb(start_at),
            "end_at":
            _cursor_pb(end_at),
        }
        if self._offset is not None:
            query_kwargs["offset"] = self._offset
        if self._limit is not None:
            query_kwargs["limit"] = wrappers_pb2.Int32Value(value=self._limit)

        return query_pb2.StructuredQuery(**query_kwargs)
예제 #2
0
    def _to_protobuf(self):
        from google.cloud.firestore_v1.proto import query_pb2

        query_kwargs = {
            "select": None,
            "from": None,
            "where": None,
            "order_by": None,
            "start_at": None,
            "end_at": None,
        }
        return query_pb2.StructuredQuery(**query_kwargs)