Skip to content

Commit 8877803

Browse files
Add invokeRunQueryRpc() (#3025)
1 parent fd12d77 commit 8877803

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

packages/firestore/src/protos/firestore_proto_api.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ export declare namespace firestoreV1ApiClientInterfaces {
314314
transaction?: string;
315315
}
316316
interface RunQueryRequest {
317+
parent?: string;
317318
structuredQuery?: StructuredQuery;
318319
transaction?: string;
319320
newTransaction?: TransactionOptions;

packages/firestore/src/remote/datastore.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
import { CredentialsProvider } from '../api/credentials';
19-
import { MaybeDocument } from '../model/document';
19+
import { MaybeDocument, Document } from '../model/document';
2020
import { DocumentKey } from '../model/document_key';
2121
import { Mutation, MutationResult } from '../model/mutation';
2222
import * as api from '../protos/firestore_proto_api';
@@ -31,6 +31,7 @@ import {
3131
WriteStreamListener
3232
} from './persistent_stream';
3333
import { AsyncQueue } from '../util/async_queue';
34+
import { Query } from '../core/query';
3435

3536
/**
3637
* Datastore and its related methods are a wrapper around the external Google
@@ -149,6 +150,33 @@ export async function invokeBatchGetDocumentsRpc(
149150
return result;
150151
}
151152

153+
export async function invokeRunQueryRpc(
154+
datastore: Datastore,
155+
query: Query
156+
): Promise<Document[]> {
157+
const datastoreImpl = debugCast(datastore, DatastoreImpl);
158+
const { structuredQuery, parent } = datastoreImpl.serializer.toQueryTarget(
159+
query.toTarget()
160+
);
161+
const params = {
162+
database: datastoreImpl.serializer.encodedDatabaseId,
163+
parent,
164+
structuredQuery
165+
};
166+
167+
const response = await datastoreImpl.invokeStreamingRPC<
168+
api.RunQueryRequest,
169+
api.RunQueryResponse
170+
>('RunQuery', params);
171+
172+
return (
173+
response
174+
// Omit RunQueryResponses that only contain readTimes.
175+
.filter(proto => !!proto.document)
176+
.map(proto => datastoreImpl.serializer.fromDocument(proto.document!))
177+
);
178+
}
179+
152180
export function newPersistentWriteStream(
153181
datastore: Datastore,
154182
queue: AsyncQueue,

0 commit comments

Comments
 (0)