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\Spanner\Resource;
19
20use Google\Service\Spanner\CreateDatabaseRequest;
21use Google\Service\Spanner\Database;
22use Google\Service\Spanner\GetDatabaseDdlResponse;
23use Google\Service\Spanner\GetIamPolicyRequest;
24use Google\Service\Spanner\ListDatabasesResponse;
25use Google\Service\Spanner\Operation;
26use Google\Service\Spanner\Policy;
27use Google\Service\Spanner\RestoreDatabaseRequest;
28use Google\Service\Spanner\Scan;
29use Google\Service\Spanner\SetIamPolicyRequest;
30use Google\Service\Spanner\SpannerEmpty;
31use Google\Service\Spanner\TestIamPermissionsRequest;
32use Google\Service\Spanner\TestIamPermissionsResponse;
33use Google\Service\Spanner\UpdateDatabaseDdlRequest;
34
35/**
36 * The "databases" collection of methods.
37 * Typical usage is:
38 *  <code>
39 *   $spannerService = new Google\Service\Spanner(...);
40 *   $databases = $spannerService->databases;
41 *  </code>
42 */
43class ProjectsInstancesDatabases extends \Google\Service\Resource
44{
45  /**
46   * Creates a new Cloud Spanner database and starts to prepare it for serving.
47   * The returned long-running operation will have a name of the format
48   * `/operations/` and can be used to track preparation of the database. The
49   * metadata field type is CreateDatabaseMetadata. The response field type is
50   * Database, if successful. (databases.create)
51   *
52   * @param string $parent Required. The name of the instance that will serve the
53   * new database. Values are of the form `projects//instances/`.
54   * @param CreateDatabaseRequest $postBody
55   * @param array $optParams Optional parameters.
56   * @return Operation
57   */
58  public function create($parent, CreateDatabaseRequest $postBody, $optParams = [])
59  {
60    $params = ['parent' => $parent, 'postBody' => $postBody];
61    $params = array_merge($params, $optParams);
62    return $this->call('create', [$params], Operation::class);
63  }
64  /**
65   * Drops (aka deletes) a Cloud Spanner database. Completed backups for the
66   * database will be retained according to their `expire_time`. Note: Cloud
67   * Spanner might continue to accept requests for a few seconds after the
68   * database has been deleted. (databases.dropDatabase)
69   *
70   * @param string $database Required. The database to be dropped.
71   * @param array $optParams Optional parameters.
72   * @return SpannerEmpty
73   */
74  public function dropDatabase($database, $optParams = [])
75  {
76    $params = ['database' => $database];
77    $params = array_merge($params, $optParams);
78    return $this->call('dropDatabase', [$params], SpannerEmpty::class);
79  }
80  /**
81   * Gets the state of a Cloud Spanner database. (databases.get)
82   *
83   * @param string $name Required. The name of the requested database. Values are
84   * of the form `projects//instances//databases/`.
85   * @param array $optParams Optional parameters.
86   * @return Database
87   */
88  public function get($name, $optParams = [])
89  {
90    $params = ['name' => $name];
91    $params = array_merge($params, $optParams);
92    return $this->call('get', [$params], Database::class);
93  }
94  /**
95   * Returns the schema of a Cloud Spanner database as a list of formatted DDL
96   * statements. This method does not show pending schema updates, those may be
97   * queried using the Operations API. (databases.getDdl)
98   *
99   * @param string $database Required. The database whose schema we wish to get.
100   * Values are of the form `projects//instances//databases/`
101   * @param array $optParams Optional parameters.
102   * @return GetDatabaseDdlResponse
103   */
104  public function getDdl($database, $optParams = [])
105  {
106    $params = ['database' => $database];
107    $params = array_merge($params, $optParams);
108    return $this->call('getDdl', [$params], GetDatabaseDdlResponse::class);
109  }
110  /**
111   * Gets the access control policy for a database or backup resource. Returns an
112   * empty policy if a database or backup exists but does not have a policy set.
113   * Authorization requires `spanner.databases.getIamPolicy` permission on
114   * resource. For backups, authorization requires `spanner.backups.getIamPolicy`
115   * permission on resource. (databases.getIamPolicy)
116   *
117   * @param string $resource REQUIRED: The Cloud Spanner resource for which the
118   * policy is being retrieved. The format is `projects//instances/` for instance
119   * resources and `projects//instances//databases/` for database resources.
120   * @param GetIamPolicyRequest $postBody
121   * @param array $optParams Optional parameters.
122   * @return Policy
123   */
124  public function getIamPolicy($resource, GetIamPolicyRequest $postBody, $optParams = [])
125  {
126    $params = ['resource' => $resource, 'postBody' => $postBody];
127    $params = array_merge($params, $optParams);
128    return $this->call('getIamPolicy', [$params], Policy::class);
129  }
130  /**
131   * Request a specific scan with Database-specific data for Cloud Key Visualizer.
132   * (databases.getScans)
133   *
134   * @param string $name Required. The unique name of the scan containing the
135   * requested information, specific to the Database service implementing this
136   * interface.
137   * @param array $optParams Optional parameters.
138   *
139   * @opt_param string endTime The upper bound for the time range to retrieve Scan
140   * data for.
141   * @opt_param string startTime These fields restrict the Database-specific
142   * information returned in the `Scan.data` field. If a `View` is provided that
143   * does not include the `Scan.data` field, these are ignored. This range of time
144   * must be entirely contained within the defined time range of the targeted
145   * scan. The lower bound for the time range to retrieve Scan data for.
146   * @opt_param string view Specifies which parts of the Scan should be returned
147   * in the response. Note, if left unspecified, the FULL view is assumed.
148   * @return Scan
149   */
150  public function getScans($name, $optParams = [])
151  {
152    $params = ['name' => $name];
153    $params = array_merge($params, $optParams);
154    return $this->call('getScans', [$params], Scan::class);
155  }
156  /**
157   * Lists Cloud Spanner databases. (databases.listProjectsInstancesDatabases)
158   *
159   * @param string $parent Required. The instance whose databases should be
160   * listed. Values are of the form `projects//instances/`.
161   * @param array $optParams Optional parameters.
162   *
163   * @opt_param int pageSize Number of databases to be returned in the response.
164   * If 0 or less, defaults to the server's maximum allowed page size.
165   * @opt_param string pageToken If non-empty, `page_token` should contain a
166   * next_page_token from a previous ListDatabasesResponse.
167   * @return ListDatabasesResponse
168   */
169  public function listProjectsInstancesDatabases($parent, $optParams = [])
170  {
171    $params = ['parent' => $parent];
172    $params = array_merge($params, $optParams);
173    return $this->call('list', [$params], ListDatabasesResponse::class);
174  }
175  /**
176   * Create a new database by restoring from a completed backup. The new database
177   * must be in the same project and in an instance with the same instance
178   * configuration as the instance containing the backup. The returned database
179   * long-running operation has a name of the format
180   * `projects//instances//databases//operations/`, and can be used to track the
181   * progress of the operation, and to cancel it. The metadata field type is
182   * RestoreDatabaseMetadata. The response type is Database, if successful.
183   * Cancelling the returned operation will stop the restore and delete the
184   * database. There can be only one database being restored into an instance at a
185   * time. Once the restore operation completes, a new restore operation can be
186   * initiated, without waiting for the optimize operation associated with the
187   * first restore to complete. (databases.restore)
188   *
189   * @param string $parent Required. The name of the instance in which to create
190   * the restored database. This instance must be in the same project and have the
191   * same instance configuration as the instance containing the source backup.
192   * Values are of the form `projects//instances/`.
193   * @param RestoreDatabaseRequest $postBody
194   * @param array $optParams Optional parameters.
195   * @return Operation
196   */
197  public function restore($parent, RestoreDatabaseRequest $postBody, $optParams = [])
198  {
199    $params = ['parent' => $parent, 'postBody' => $postBody];
200    $params = array_merge($params, $optParams);
201    return $this->call('restore', [$params], Operation::class);
202  }
203  /**
204   * Sets the access control policy on a database or backup resource. Replaces any
205   * existing policy. Authorization requires `spanner.databases.setIamPolicy`
206   * permission on resource. For backups, authorization requires
207   * `spanner.backups.setIamPolicy` permission on resource.
208   * (databases.setIamPolicy)
209   *
210   * @param string $resource REQUIRED: The Cloud Spanner resource for which the
211   * policy is being set. The format is `projects//instances/` for instance
212   * resources and `projects//instances//databases/` for databases resources.
213   * @param SetIamPolicyRequest $postBody
214   * @param array $optParams Optional parameters.
215   * @return Policy
216   */
217  public function setIamPolicy($resource, SetIamPolicyRequest $postBody, $optParams = [])
218  {
219    $params = ['resource' => $resource, 'postBody' => $postBody];
220    $params = array_merge($params, $optParams);
221    return $this->call('setIamPolicy', [$params], Policy::class);
222  }
223  /**
224   * Returns permissions that the caller has on the specified database or backup
225   * resource. Attempting this RPC on a non-existent Cloud Spanner database will
226   * result in a NOT_FOUND error if the user has `spanner.databases.list`
227   * permission on the containing Cloud Spanner instance. Otherwise returns an
228   * empty set of permissions. Calling this method on a backup that does not exist
229   * will result in a NOT_FOUND error if the user has `spanner.backups.list`
230   * permission on the containing instance. (databases.testIamPermissions)
231   *
232   * @param string $resource REQUIRED: The Cloud Spanner resource for which
233   * permissions are being tested. The format is `projects//instances/` for
234   * instance resources and `projects//instances//databases/` for database
235   * resources.
236   * @param TestIamPermissionsRequest $postBody
237   * @param array $optParams Optional parameters.
238   * @return TestIamPermissionsResponse
239   */
240  public function testIamPermissions($resource, TestIamPermissionsRequest $postBody, $optParams = [])
241  {
242    $params = ['resource' => $resource, 'postBody' => $postBody];
243    $params = array_merge($params, $optParams);
244    return $this->call('testIamPermissions', [$params], TestIamPermissionsResponse::class);
245  }
246  /**
247   * Updates the schema of a Cloud Spanner database by creating/altering/dropping
248   * tables, columns, indexes, etc. The returned long-running operation will have
249   * a name of the format `/operations/` and can be used to track execution of the
250   * schema change(s). The metadata field type is UpdateDatabaseDdlMetadata. The
251   * operation has no response. (databases.updateDdl)
252   *
253   * @param string $database Required. The database to update.
254   * @param UpdateDatabaseDdlRequest $postBody
255   * @param array $optParams Optional parameters.
256   * @return Operation
257   */
258  public function updateDdl($database, UpdateDatabaseDdlRequest $postBody, $optParams = [])
259  {
260    $params = ['database' => $database, 'postBody' => $postBody];
261    $params = array_merge($params, $optParams);
262    return $this->call('updateDdl', [$params], Operation::class);
263  }
264}
265
266// Adding a class alias for backwards compatibility with the previous class name.
267class_alias(ProjectsInstancesDatabases::class, 'Google_Service_Spanner_Resource_ProjectsInstancesDatabases');
268