Esempio n. 1
0
        public async Task GqlQueryAsync()
        {
            string projectId   = _fixture.ProjectId;
            string namespaceId = _fixture.NamespaceId;

            // Snippet: RunQueryAsync(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"
                                    } } },
            };
            DatastoreAsyncQueryResults results = db.RunQueryAsync(gqlQuery);
            // DatastoreAsyncQueryResults implements IAsyncEnumerable<Entity>, but you can
            // call AsEntityResults(), AsBatches() or AsResponses() to see the query
            // results in whatever way makes most sense for your application.
            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 AsBatches()
        {
            var results  = new DatastoreAsyncQueryResults(_responses.Select(r => r.Clone()).ToAsyncEnumerable());
            var expected = new[] { _responses[0].Batch, _responses[1].Batch, _responses[2].Batch, _responses[3].Batch };

            Assert.Equal(expected, await results.AsBatches().ToList());
        }
Esempio n. 3
0
        public async Task StructuredQueryAsync()
        {
            string projectId   = _fixture.ProjectId;
            string namespaceId = _fixture.NamespaceId;

            // Snippet: RunQueryAsync(Query,*,*)
            DatastoreDb db    = DatastoreDb.Create(projectId, namespaceId);
            Query       query = new Query("book")
            {
                Filter = Filter.Equal("author", "Jane Austen")
            };
            DatastoreAsyncQueryResults results = db.RunQueryAsync(query);
            // DatastoreAsyncQueryResults implements IAsyncEnumerable<Entity>, but you can
            // call AsEntityResults(), AsBatches() or AsResponses() to see the query
            // results in whatever way makes most sense for your application.
            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 AsEntityResults()
        {
            var results  = new DatastoreAsyncQueryResults(_responses.Select(r => r.Clone()).ToAsyncEnumerable());
            var expected = _entityResults.ToList();

            expected[4].Cursor  = _responses[1].Batch.EndCursor;
            expected[14].Cursor = _responses[2].Batch.EndCursor;
            expected[19].Cursor = _responses[3].Batch.EndCursor;
            Assert.Equal(expected, await results.AsEntityResults().ToList());
        }
        public async Task AsEntities()
        {
            var results = new DatastoreAsyncQueryResults(_responses.Select(r => r.Clone()).ToAsyncEnumerable());

            Assert.Equal(_entities, await results.ToList());
        }