-
Notifications
You must be signed in to change notification settings - Fork 948
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
Add invokeRunQueryRpc() #3025
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
|
@@ -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 | ||
|
@@ -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 | ||
// Filter RunQueryResponses that only contain readTimes. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ultranit: consider s/Filter/Omit/ ("filter" has the unfortunate ambiguity in that it might refer to either the part that is left in place or the part that gets removed. It's clear enough from the context, but I still think something like "omit" is slightly better). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: from reading the PR description, it appears that only the last element may not contain a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The PR description reflects the behavior that I have observed. The protocol state though that it is also valid to not provide a document mid-stream as a way to report status. |
||
.filter(proto => !!proto.document) | ||
.map(proto => datastoreImpl.serializer.fromDocument(proto.document!)) | ||
); | ||
} | ||
|
||
export function newPersistentWriteStream( | ||
datastore: Datastore, | ||
queue: AsyncQueue, | ||
|
There was a problem hiding this comment.
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 toresponses
,streamingResponse
, etc.?