Skip to content

Add invokeRunQueryRpc() #3025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/firestore/src/protos/firestore_proto_api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ export declare namespace firestoreV1ApiClientInterfaces {
transaction?: string;
}
interface RunQueryRequest {
parent?: string;
structuredQuery?: StructuredQuery;
transaction?: string;
newTransaction?: TransactionOptions;
Expand Down
30 changes: 29 additions & 1 deletion packages/firestore/src/remote/datastore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import { CredentialsProvider } from '../api/credentials';
import { MaybeDocument } from '../model/document';
import { MaybeDocument, Document } from '../model/document';
import { DocumentKey } from '../model/document_key';
import { Mutation, MutationResult } from '../model/mutation';
import * as api from '../protos/firestore_proto_api';
Expand All @@ -31,6 +31,7 @@ import {
WriteStreamListener
} from './persistent_stream';
import { AsyncQueue } from '../util/async_queue';
import { Query } from '../core/query';

/**
* Datastore and its related methods are a wrapper around the external Google
Expand Down Expand Up @@ -149,6 +150,33 @@ export async function invokeBatchGetDocumentsRpc(
return result;
}

export async function invokeRunQueryRpc(
datastore: Datastore,
query: Query
): Promise<Document[]> {
const datastoreImpl = debugCast(datastore, DatastoreImpl);
const { structuredQuery, parent } = datastoreImpl.serializer.toQueryTarget(
query.toTarget()
);
const params = {
database: datastoreImpl.serializer.encodedDatabaseId,
parent,
structuredQuery
};

const response = await datastoreImpl.invokeStreamingRPC<
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: it appears that response is actually a container, perhaps rename it to responses, streamingResponse, etc.?

api.RunQueryRequest,
api.RunQueryResponse
>('RunQuery', params);

return (
response
// Omit RunQueryResponses that only contain readTimes.
.filter(proto => !!proto.document)
.map(proto => datastoreImpl.serializer.fromDocument(proto.document!))
);
}

export function newPersistentWriteStream(
datastore: Datastore,
queue: AsyncQueue,
Expand Down