Skip to content

Commit

Permalink
Add invokeRunQueryRpc() (#3025)
Browse files Browse the repository at this point in the history
  • Loading branch information
schmidt-sebastian authored May 6, 2020
1 parent fd12d77 commit 8877803
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
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<
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

0 comments on commit 8877803

Please sign in to comment.