Example #1
0
        /// <summary>
        /// Executes the given GQL query in this transaction, returning a result set that can be viewed as an asynchronous
        /// sequence of entities, entity results (with cursors), batches, or raw API responses.
        /// </summary>
        /// <remarks>
        /// <para>
        /// Using a transaction ensures that a commit operation will fail if any of the entities returned
        /// by this query have been modified while the transaction is active. Note that modifications performed
        /// as part of this operation are not reflected in the query results.
        /// </para>
        /// <para>
        /// The results are requested lazily: no API calls will be made until the application starts
        /// iterating over the results. Iterating over the same <see cref="DatastoreQueryResults"/> object
        /// multiple times will execute the query again, potentially returning different results.
        /// </para>
        /// </remarks>
        /// <param name="query">The query to execute. Must not be null.</param>
        /// <param name="partitionId">The partition in which to execute the query. May be null, in which case
        /// the query is executed in the partition associated with the empty namespace in the project used by this transaction.</param>
        /// <param name="callSettings">If not null, applies overrides to RPC calls.</param>
        /// <returns>A <see cref="DatastoreQueryResults"/> representing the result of the query.</returns>
        public DatastoreAsyncQueryResults RunQueryAsync(GqlQuery gqlQuery, PartitionId partitionId, CallSettings callSettings = null)
        {
            GaxPreconditions.CheckNotNull(gqlQuery, nameof(gqlQuery));
            var request = new RunQueryRequest
            {
                ProjectId   = _projectId,
                PartitionId = partitionId,
                GqlQuery    = gqlQuery,
                ReadOptions = _readOptions
            };
            var streamer = new QueryStreamer(request, _client.RunQueryApiCall, callSettings);

            return(new DatastoreAsyncQueryResults(streamer.Async()));
        }
        /// <inheritdoc/>
        public override DatastoreAsyncQueryResults RunQueryAsync(
            Query query,
            ReadConsistency?readConsistency = null,
            CallSettings callSettings       = null)
        {
            GaxPreconditions.CheckNotNull(query, nameof(query));
            var request = new RunQueryRequest
            {
                ProjectId   = ProjectId,
                PartitionId = _partitionId,
                Query       = query,
                ReadOptions = GetReadOptions(readConsistency)
            };
            var streamer = new QueryStreamer(request, Client.RunQueryApiCall, callSettings);

            return(new DatastoreAsyncQueryResults(streamer.Async()));
        }