1<?php
2/*
3 * Copyright 2014 Google Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6 * use this file except in compliance with the License. You may obtain a copy of
7 * the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 * License for the specific language governing permissions and limitations under
15 * the License.
16 */
17
18namespace Google\Service\Firestore\Resource;
19
20use Google\Service\Firestore\BatchGetDocumentsRequest;
21use Google\Service\Firestore\BatchGetDocumentsResponse;
22use Google\Service\Firestore\BatchWriteRequest;
23use Google\Service\Firestore\BatchWriteResponse;
24use Google\Service\Firestore\BeginTransactionRequest;
25use Google\Service\Firestore\BeginTransactionResponse;
26use Google\Service\Firestore\CommitRequest;
27use Google\Service\Firestore\CommitResponse;
28use Google\Service\Firestore\Document;
29use Google\Service\Firestore\FirestoreEmpty;
30use Google\Service\Firestore\ListCollectionIdsRequest;
31use Google\Service\Firestore\ListCollectionIdsResponse;
32use Google\Service\Firestore\ListDocumentsResponse;
33use Google\Service\Firestore\ListenRequest;
34use Google\Service\Firestore\ListenResponse;
35use Google\Service\Firestore\PartitionQueryRequest;
36use Google\Service\Firestore\PartitionQueryResponse;
37use Google\Service\Firestore\RollbackRequest;
38use Google\Service\Firestore\RunAggregationQueryRequest;
39use Google\Service\Firestore\RunAggregationQueryResponse;
40use Google\Service\Firestore\RunQueryRequest;
41use Google\Service\Firestore\RunQueryResponse;
42use Google\Service\Firestore\WriteRequest;
43use Google\Service\Firestore\WriteResponse;
44
45/**
46 * The "documents" collection of methods.
47 * Typical usage is:
48 *  <code>
49 *   $firestoreService = new Google\Service\Firestore(...);
50 *   $documents = $firestoreService->documents;
51 *  </code>
52 */
53class ProjectsDatabasesDocuments extends \Google\Service\Resource
54{
55  /**
56   * Gets multiple documents. Documents returned by this method are not guaranteed
57   * to be returned in the same order that they were requested.
58   * (documents.batchGet)
59   *
60   * @param string $database Required. The database name. In the format:
61   * `projects/{project_id}/databases/{database_id}`.
62   * @param BatchGetDocumentsRequest $postBody
63   * @param array $optParams Optional parameters.
64   * @return BatchGetDocumentsResponse
65   */
66  public function batchGet($database, BatchGetDocumentsRequest $postBody, $optParams = [])
67  {
68    $params = ['database' => $database, 'postBody' => $postBody];
69    $params = array_merge($params, $optParams);
70    return $this->call('batchGet', [$params], BatchGetDocumentsResponse::class);
71  }
72  /**
73   * Applies a batch of write operations. The BatchWrite method does not apply the
74   * write operations atomically and can apply them out of order. Method does not
75   * allow more than one write per document. Each write succeeds or fails
76   * independently. See the BatchWriteResponse for the success status of each
77   * write. If you require an atomically applied set of writes, use Commit
78   * instead. (documents.batchWrite)
79   *
80   * @param string $database Required. The database name. In the format:
81   * `projects/{project_id}/databases/{database_id}`.
82   * @param BatchWriteRequest $postBody
83   * @param array $optParams Optional parameters.
84   * @return BatchWriteResponse
85   */
86  public function batchWrite($database, BatchWriteRequest $postBody, $optParams = [])
87  {
88    $params = ['database' => $database, 'postBody' => $postBody];
89    $params = array_merge($params, $optParams);
90    return $this->call('batchWrite', [$params], BatchWriteResponse::class);
91  }
92  /**
93   * Starts a new transaction. (documents.beginTransaction)
94   *
95   * @param string $database Required. The database name. In the format:
96   * `projects/{project_id}/databases/{database_id}`.
97   * @param BeginTransactionRequest $postBody
98   * @param array $optParams Optional parameters.
99   * @return BeginTransactionResponse
100   */
101  public function beginTransaction($database, BeginTransactionRequest $postBody, $optParams = [])
102  {
103    $params = ['database' => $database, 'postBody' => $postBody];
104    $params = array_merge($params, $optParams);
105    return $this->call('beginTransaction', [$params], BeginTransactionResponse::class);
106  }
107  /**
108   * Commits a transaction, while optionally updating documents.
109   * (documents.commit)
110   *
111   * @param string $database Required. The database name. In the format:
112   * `projects/{project_id}/databases/{database_id}`.
113   * @param CommitRequest $postBody
114   * @param array $optParams Optional parameters.
115   * @return CommitResponse
116   */
117  public function commit($database, CommitRequest $postBody, $optParams = [])
118  {
119    $params = ['database' => $database, 'postBody' => $postBody];
120    $params = array_merge($params, $optParams);
121    return $this->call('commit', [$params], CommitResponse::class);
122  }
123  /**
124   * Creates a new document. (documents.createDocument)
125   *
126   * @param string $parent Required. The parent resource. For example:
127   * `projects/{project_id}/databases/{database_id}/documents` or `projects/{proje
128   * ct_id}/databases/{database_id}/documents/chatrooms/{chatroom_id}`
129   * @param string $collectionId Required. The collection ID, relative to
130   * `parent`, to list. For example: `chatrooms`.
131   * @param Document $postBody
132   * @param array $optParams Optional parameters.
133   *
134   * @opt_param string documentId The client-assigned document ID to use for this
135   * document. Optional. If not specified, an ID will be assigned by the service.
136   * @opt_param string mask.fieldPaths The list of field paths in the mask. See
137   * Document.fields for a field path syntax reference.
138   * @return Document
139   */
140  public function createDocument($parent, $collectionId, Document $postBody, $optParams = [])
141  {
142    $params = ['parent' => $parent, 'collectionId' => $collectionId, 'postBody' => $postBody];
143    $params = array_merge($params, $optParams);
144    return $this->call('createDocument', [$params], Document::class);
145  }
146  /**
147   * Deletes a document. (documents.delete)
148   *
149   * @param string $name Required. The resource name of the Document to delete. In
150   * the format:
151   * `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
152   * @param array $optParams Optional parameters.
153   *
154   * @opt_param bool currentDocument.exists When set to `true`, the target
155   * document must exist. When set to `false`, the target document must not exist.
156   * @opt_param string currentDocument.updateTime When set, the target document
157   * must exist and have been last updated at that time. Timestamp must be
158   * microsecond aligned.
159   * @return FirestoreEmpty
160   */
161  public function delete($name, $optParams = [])
162  {
163    $params = ['name' => $name];
164    $params = array_merge($params, $optParams);
165    return $this->call('delete', [$params], FirestoreEmpty::class);
166  }
167  /**
168   * Gets a single document. (documents.get)
169   *
170   * @param string $name Required. The resource name of the Document to get. In
171   * the format:
172   * `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
173   * @param array $optParams Optional parameters.
174   *
175   * @opt_param string mask.fieldPaths The list of field paths in the mask. See
176   * Document.fields for a field path syntax reference.
177   * @opt_param string readTime Reads the version of the document at the given
178   * time. This may not be older than 270 seconds.
179   * @opt_param string transaction Reads the document in a transaction.
180   * @return Document
181   */
182  public function get($name, $optParams = [])
183  {
184    $params = ['name' => $name];
185    $params = array_merge($params, $optParams);
186    return $this->call('get', [$params], Document::class);
187  }
188  /**
189   * Lists documents. (documents.listProjectsDatabasesDocuments)
190   *
191   * @param string $parent Required. The parent resource name. In the format:
192   * `projects/{project_id}/databases/{database_id}/documents` or
193   * `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
194   * For example: `projects/my-project/databases/my-database/documents` or
195   * `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom`
196   * @param string $collectionId Required. The collection ID, relative to
197   * `parent`, to list. For example: `chatrooms` or `messages`.
198   * @param array $optParams Optional parameters.
199   *
200   * @opt_param string mask.fieldPaths The list of field paths in the mask. See
201   * Document.fields for a field path syntax reference.
202   * @opt_param string orderBy The order to sort results by. For example:
203   * `priority desc, name`.
204   * @opt_param int pageSize The maximum number of documents to return.
205   * @opt_param string pageToken The `next_page_token` value returned from a
206   * previous List request, if any.
207   * @opt_param string readTime Reads documents as they were at the given time.
208   * This may not be older than 270 seconds.
209   * @opt_param bool showMissing If the list should show missing documents. A
210   * missing document is a document that does not exist but has sub-documents.
211   * These documents will be returned with a key but will not have fields,
212   * Document.create_time, or Document.update_time set. Requests with
213   * `show_missing` may not specify `where` or `order_by`.
214   * @opt_param string transaction Reads documents in a transaction.
215   * @return ListDocumentsResponse
216   */
217  public function listProjectsDatabasesDocuments($parent, $collectionId, $optParams = [])
218  {
219    $params = ['parent' => $parent, 'collectionId' => $collectionId];
220    $params = array_merge($params, $optParams);
221    return $this->call('list', [$params], ListDocumentsResponse::class);
222  }
223  /**
224   * Lists all the collection IDs underneath a document.
225   * (documents.listCollectionIds)
226   *
227   * @param string $parent Required. The parent document. In the format:
228   * `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
229   * For example: `projects/my-project/databases/my-database/documents/chatrooms
230   * /my-chatroom`
231   * @param ListCollectionIdsRequest $postBody
232   * @param array $optParams Optional parameters.
233   * @return ListCollectionIdsResponse
234   */
235  public function listCollectionIds($parent, ListCollectionIdsRequest $postBody, $optParams = [])
236  {
237    $params = ['parent' => $parent, 'postBody' => $postBody];
238    $params = array_merge($params, $optParams);
239    return $this->call('listCollectionIds', [$params], ListCollectionIdsResponse::class);
240  }
241  /**
242   * Lists documents. (documents.listDocuments)
243   *
244   * @param string $parent Required. The parent resource name. In the format:
245   * `projects/{project_id}/databases/{database_id}/documents` or
246   * `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
247   * For example: `projects/my-project/databases/my-database/documents` or
248   * `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom`
249   * @param string $collectionId Required. The collection ID, relative to
250   * `parent`, to list. For example: `chatrooms` or `messages`.
251   * @param array $optParams Optional parameters.
252   *
253   * @opt_param string mask.fieldPaths The list of field paths in the mask. See
254   * Document.fields for a field path syntax reference.
255   * @opt_param string orderBy The order to sort results by. For example:
256   * `priority desc, name`.
257   * @opt_param int pageSize The maximum number of documents to return.
258   * @opt_param string pageToken The `next_page_token` value returned from a
259   * previous List request, if any.
260   * @opt_param string readTime Reads documents as they were at the given time.
261   * This may not be older than 270 seconds.
262   * @opt_param bool showMissing If the list should show missing documents. A
263   * missing document is a document that does not exist but has sub-documents.
264   * These documents will be returned with a key but will not have fields,
265   * Document.create_time, or Document.update_time set. Requests with
266   * `show_missing` may not specify `where` or `order_by`.
267   * @opt_param string transaction Reads documents in a transaction.
268   * @return ListDocumentsResponse
269   */
270  public function listDocuments($parent, $collectionId, $optParams = [])
271  {
272    $params = ['parent' => $parent, 'collectionId' => $collectionId];
273    $params = array_merge($params, $optParams);
274    return $this->call('listDocuments', [$params], ListDocumentsResponse::class);
275  }
276  /**
277   * Listens to changes. (documents.listen)
278   *
279   * @param string $database Required. The database name. In the format:
280   * `projects/{project_id}/databases/{database_id}`.
281   * @param ListenRequest $postBody
282   * @param array $optParams Optional parameters.
283   * @return ListenResponse
284   */
285  public function listen($database, ListenRequest $postBody, $optParams = [])
286  {
287    $params = ['database' => $database, 'postBody' => $postBody];
288    $params = array_merge($params, $optParams);
289    return $this->call('listen', [$params], ListenResponse::class);
290  }
291  /**
292   * Partitions a query by returning partition cursors that can be used to run the
293   * query in parallel. The returned partition cursors are split points that can
294   * be used by RunQuery as starting/end points for the query results.
295   * (documents.partitionQuery)
296   *
297   * @param string $parent Required. The parent resource name. In the format:
298   * `projects/{project_id}/databases/{database_id}/documents`. Document resource
299   * names are not supported; only database resource names can be specified.
300   * @param PartitionQueryRequest $postBody
301   * @param array $optParams Optional parameters.
302   * @return PartitionQueryResponse
303   */
304  public function partitionQuery($parent, PartitionQueryRequest $postBody, $optParams = [])
305  {
306    $params = ['parent' => $parent, 'postBody' => $postBody];
307    $params = array_merge($params, $optParams);
308    return $this->call('partitionQuery', [$params], PartitionQueryResponse::class);
309  }
310  /**
311   * Updates or inserts a document. (documents.patch)
312   *
313   * @param string $name The resource name of the document, for example
314   * `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
315   * @param Document $postBody
316   * @param array $optParams Optional parameters.
317   *
318   * @opt_param bool currentDocument.exists When set to `true`, the target
319   * document must exist. When set to `false`, the target document must not exist.
320   * @opt_param string currentDocument.updateTime When set, the target document
321   * must exist and have been last updated at that time. Timestamp must be
322   * microsecond aligned.
323   * @opt_param string mask.fieldPaths The list of field paths in the mask. See
324   * Document.fields for a field path syntax reference.
325   * @opt_param string updateMask.fieldPaths The list of field paths in the mask.
326   * See Document.fields for a field path syntax reference.
327   * @return Document
328   */
329  public function patch($name, Document $postBody, $optParams = [])
330  {
331    $params = ['name' => $name, 'postBody' => $postBody];
332    $params = array_merge($params, $optParams);
333    return $this->call('patch', [$params], Document::class);
334  }
335  /**
336   * Rolls back a transaction. (documents.rollback)
337   *
338   * @param string $database Required. The database name. In the format:
339   * `projects/{project_id}/databases/{database_id}`.
340   * @param RollbackRequest $postBody
341   * @param array $optParams Optional parameters.
342   * @return FirestoreEmpty
343   */
344  public function rollback($database, RollbackRequest $postBody, $optParams = [])
345  {
346    $params = ['database' => $database, 'postBody' => $postBody];
347    $params = array_merge($params, $optParams);
348    return $this->call('rollback', [$params], FirestoreEmpty::class);
349  }
350  /**
351   * Runs an aggregation query. Rather than producing Document results like
352   * Firestore.RunQuery, this API allows running an aggregation to produce a
353   * series of AggregationResult server-side. High-Level Example: ``` -- Return
354   * the number of documents in table given a filter. SELECT COUNT(*) FROM (
355   * SELECT * FROM k where a = true ); ``` (documents.runAggregationQuery)
356   *
357   * @param string $parent Required. The parent resource name. In the format:
358   * `projects/{project_id}/databases/{database_id}/documents` or
359   * `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
360   * For example: `projects/my-project/databases/my-database/documents` or
361   * `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom`
362   * @param RunAggregationQueryRequest $postBody
363   * @param array $optParams Optional parameters.
364   * @return RunAggregationQueryResponse
365   */
366  public function runAggregationQuery($parent, RunAggregationQueryRequest $postBody, $optParams = [])
367  {
368    $params = ['parent' => $parent, 'postBody' => $postBody];
369    $params = array_merge($params, $optParams);
370    return $this->call('runAggregationQuery', [$params], RunAggregationQueryResponse::class);
371  }
372  /**
373   * Runs a query. (documents.runQuery)
374   *
375   * @param string $parent Required. The parent resource name. In the format:
376   * `projects/{project_id}/databases/{database_id}/documents` or
377   * `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
378   * For example: `projects/my-project/databases/my-database/documents` or
379   * `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom`
380   * @param RunQueryRequest $postBody
381   * @param array $optParams Optional parameters.
382   * @return RunQueryResponse
383   */
384  public function runQuery($parent, RunQueryRequest $postBody, $optParams = [])
385  {
386    $params = ['parent' => $parent, 'postBody' => $postBody];
387    $params = array_merge($params, $optParams);
388    return $this->call('runQuery', [$params], RunQueryResponse::class);
389  }
390  /**
391   * Streams batches of document updates and deletes, in order. (documents.write)
392   *
393   * @param string $database Required. The database name. In the format:
394   * `projects/{project_id}/databases/{database_id}`. This is only required in the
395   * first message.
396   * @param WriteRequest $postBody
397   * @param array $optParams Optional parameters.
398   * @return WriteResponse
399   */
400  public function write($database, WriteRequest $postBody, $optParams = [])
401  {
402    $params = ['database' => $database, 'postBody' => $postBody];
403    $params = array_merge($params, $optParams);
404    return $this->call('write', [$params], WriteResponse::class);
405  }
406}
407
408// Adding a class alias for backwards compatibility with the previous class name.
409class_alias(ProjectsDatabasesDocuments::class, 'Google_Service_Firestore_Resource_ProjectsDatabasesDocuments');
410