public async Task LazyGqlQueryAsync() { string projectId = _fixture.ProjectId; string namespaceId = _fixture.NamespaceId; // Snippet: RunQueryLazilyAsync(GqlQuery,*,*) DatastoreDb db = DatastoreDb.Create(projectId, namespaceId); GqlQuery gqlQuery = new GqlQuery { QueryString = "SELECT * FROM book WHERE author = @author", NamedBindings = { { "author", new GqlQueryParameter { Value = "Jane Austen" } } }, }; AsyncLazyDatastoreQuery results = db.RunQueryLazilyAsync(gqlQuery); // AsyncLazyDatastoreQuery implements IAsyncEnumerable<Entity>, but you can // call AsResponses() to see the raw RPC responses, or // GetAllResultsAsync() to get all the results into memory, complete with // the end cursor and the reason for the query finishing. await results.ForEachAsync(entity => { Console.WriteLine(entity); }); // End snippet // This will run the query again, admittedly... List <Entity> entities = await results.ToList(); Assert.Equal(1, entities.Count); Entity book = entities[0]; Assert.Equal("Jane Austen", (string)book["author"]); Assert.Equal("Pride and Prejudice", (string)book["title"]); }
public async Task LazyStructuredQueryAsync() { string projectId = _fixture.ProjectId; string namespaceId = _fixture.NamespaceId; // Snippet: RunQueryLazilyAsync(Query,*,*) DatastoreDb db = DatastoreDb.Create(projectId, namespaceId); Query query = new Query("book") { Filter = Filter.Equal("author", "Jane Austen") }; AsyncLazyDatastoreQuery results = db.RunQueryLazilyAsync(query); // AsyncLazyDatastoreQuery implements IAsyncEnumerable<Entity>, but you can // call AsResponses() to see the raw RPC responses, or // GetAllResultsAsync() to get all the results into memory, complete with // the end cursor and the reason for the query finishing. await results.ForEachAsync(entity => { Console.WriteLine(entity); }); // End snippet // This will run the query again, admittedly... List <Entity> entities = await results.ToListAsync(); Assert.Equal(1, entities.Count); Entity book = entities[0]; Assert.Equal("Jane Austen", (string)book["author"]); Assert.Equal("Pride and Prejudice", (string)book["title"]); }
public async Task GetAllResultsAsync() { var query = new AsyncLazyDatastoreQuery(_responses.Select(r => r.Clone()).ToAsyncEnumerable()); var results = await query.GetAllResultsAsync(); Assert.Equal(_entities, results.Entities.ToArray()); Assert.Equal(MoreResultsType.MoreResultsAfterLimit, results.MoreResults); Assert.Equal(ByteString.CopyFromUtf8("after-batch-4"), results.EndCursor); }
public async Task AsResponses() { var query = new AsyncLazyDatastoreQuery(_responses.Select(r => r.Clone()).ToAsyncEnumerable()); Assert.Equal(_responses, await query.AsResponses().ToListAsync()); }