google_cloud_spanner_admin_database_v1/client.rs
1// Copyright 2025 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15// Code generated by sidekick. DO NOT EDIT.
16#![allow(rustdoc::bare_urls)]
17#![allow(rustdoc::broken_intra_doc_links)]
18#![allow(rustdoc::invalid_html_tags)]
19#![allow(rustdoc::redundant_explicit_links)]
20
21/// Implements a client for the Cloud Spanner API.
22///
23/// # Example
24/// ```
25/// # use google_cloud_spanner_admin_database_v1::client::DatabaseAdmin;
26/// use google_cloud_gax::paginator::ItemPaginator as _;
27/// async fn sample(
28/// parent: &str,
29/// ) -> anyhow::Result<()> {
30/// let client = DatabaseAdmin::builder().build().await?;
31/// let mut list = client.list_databases()
32/// .set_parent(parent)
33/// .by_item();
34/// while let Some(item) = list.next().await.transpose()? {
35/// println!("{:?}", item);
36/// }
37/// Ok(())
38/// }
39/// ```
40///
41/// # Service Description
42///
43/// Cloud Spanner Database Admin API
44///
45/// The Cloud Spanner Database Admin API can be used to:
46///
47/// * create, drop, and list databases
48/// * update the schema of pre-existing databases
49/// * create, delete, copy and list backups for a database
50/// * restore a database from an existing backup
51///
52/// # Configuration
53///
54/// To configure `DatabaseAdmin` use the `with_*` methods in the type returned
55/// by [builder()][DatabaseAdmin::builder]. The default configuration should
56/// work for most applications. Common configuration changes include
57///
58/// * [with_endpoint()]: by default this client uses the global default endpoint
59/// (`https://spanner.googleapis.com`). Applications using regional
60/// endpoints or running in restricted networks (e.g. a network configured
61/// with [Private Google Access with VPC Service Controls]) may want to
62/// override this default.
63/// * [with_credentials()]: by default this client uses
64/// [Application Default Credentials]. Applications using custom
65/// authentication may need to override this default.
66///
67/// [with_endpoint()]: super::builder::database_admin::ClientBuilder::with_endpoint
68/// [with_credentials()]: super::builder::database_admin::ClientBuilder::with_credentials
69/// [Private Google Access with VPC Service Controls]: https://cloud.google.com/vpc-service-controls/docs/private-connectivity
70/// [Application Default Credentials]: https://cloud.google.com/docs/authentication#adc
71///
72/// # Pooling and Cloning
73///
74/// `DatabaseAdmin` holds a connection pool internally, it is advised to
75/// create one and reuse it. You do not need to wrap `DatabaseAdmin` in
76/// an [Rc](std::rc::Rc) or [Arc](std::sync::Arc) to reuse it, because it
77/// already uses an `Arc` internally.
78#[derive(Clone, Debug)]
79pub struct DatabaseAdmin {
80 inner: std::sync::Arc<dyn super::stub::dynamic::DatabaseAdmin>,
81}
82
83impl DatabaseAdmin {
84 /// Returns a builder for [DatabaseAdmin].
85 ///
86 /// ```
87 /// # async fn sample() -> google_cloud_gax::client_builder::Result<()> {
88 /// # use google_cloud_spanner_admin_database_v1::client::DatabaseAdmin;
89 /// let client = DatabaseAdmin::builder().build().await?;
90 /// # Ok(()) }
91 /// ```
92 pub fn builder() -> super::builder::database_admin::ClientBuilder {
93 crate::new_client_builder(super::builder::database_admin::client::Factory)
94 }
95
96 /// Creates a new client from the provided stub.
97 ///
98 /// The most common case for calling this function is in tests mocking the
99 /// client's behavior.
100 pub fn from_stub<T>(stub: impl Into<std::sync::Arc<T>>) -> Self
101 where
102 T: super::stub::DatabaseAdmin + 'static,
103 {
104 Self { inner: stub.into() }
105 }
106
107 pub(crate) async fn new(
108 config: gaxi::options::ClientConfig,
109 ) -> crate::ClientBuilderResult<Self> {
110 let inner = Self::build_inner(config).await?;
111 Ok(Self { inner })
112 }
113
114 async fn build_inner(
115 conf: gaxi::options::ClientConfig,
116 ) -> crate::ClientBuilderResult<std::sync::Arc<dyn super::stub::dynamic::DatabaseAdmin>> {
117 if gaxi::options::tracing_enabled(&conf) {
118 return Ok(std::sync::Arc::new(Self::build_with_tracing(conf).await?));
119 }
120 Ok(std::sync::Arc::new(Self::build_transport(conf).await?))
121 }
122
123 async fn build_transport(
124 conf: gaxi::options::ClientConfig,
125 ) -> crate::ClientBuilderResult<impl super::stub::DatabaseAdmin> {
126 super::transport::DatabaseAdmin::new(conf).await
127 }
128
129 async fn build_with_tracing(
130 conf: gaxi::options::ClientConfig,
131 ) -> crate::ClientBuilderResult<impl super::stub::DatabaseAdmin> {
132 Self::build_transport(conf)
133 .await
134 .map(super::tracing::DatabaseAdmin::new)
135 }
136
137 /// Lists Cloud Spanner databases.
138 ///
139 /// # Example
140 /// ```
141 /// # use google_cloud_spanner_admin_database_v1::client::DatabaseAdmin;
142 /// use google_cloud_gax::paginator::ItemPaginator as _;
143 /// use google_cloud_spanner_admin_database_v1::Result;
144 /// async fn sample(
145 /// client: &DatabaseAdmin, parent: &str
146 /// ) -> Result<()> {
147 /// let mut list = client.list_databases()
148 /// .set_parent(parent)
149 /// .by_item();
150 /// while let Some(item) = list.next().await.transpose()? {
151 /// println!("{:?}", item);
152 /// }
153 /// Ok(())
154 /// }
155 /// ```
156 pub fn list_databases(&self) -> super::builder::database_admin::ListDatabases {
157 super::builder::database_admin::ListDatabases::new(self.inner.clone())
158 }
159
160 /// Creates a new Cloud Spanner database and starts to prepare it for serving.
161 /// The returned [long-running operation][google.longrunning.Operation] will
162 /// have a name of the format `<database_name>/operations/<operation_id>` and
163 /// can be used to track preparation of the database. The
164 /// [metadata][google.longrunning.Operation.metadata] field type is
165 /// [CreateDatabaseMetadata][google.spanner.admin.database.v1.CreateDatabaseMetadata].
166 /// The [response][google.longrunning.Operation.response] field type is
167 /// [Database][google.spanner.admin.database.v1.Database], if successful.
168 ///
169 /// [google.longrunning.Operation]: google_cloud_longrunning::model::Operation
170 /// [google.longrunning.Operation.metadata]: google_cloud_longrunning::model::Operation::metadata
171 /// [google.longrunning.Operation.response]: google_cloud_longrunning::model::Operation::result
172 /// [google.spanner.admin.database.v1.CreateDatabaseMetadata]: crate::model::CreateDatabaseMetadata
173 /// [google.spanner.admin.database.v1.Database]: crate::model::Database
174 ///
175 /// # Long running operations
176 ///
177 /// This method is used to start, and/or poll a [long-running Operation].
178 /// The [Working with long-running operations] chapter in the [user guide]
179 /// covers these operations in detail.
180 ///
181 /// [long-running operation]: https://google.aip.dev/151
182 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
183 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
184 ///
185 /// # Example
186 /// ```
187 /// # use google_cloud_spanner_admin_database_v1::client::DatabaseAdmin;
188 /// use google_cloud_lro::Poller;
189 /// use google_cloud_spanner_admin_database_v1::Result;
190 /// async fn sample(
191 /// client: &DatabaseAdmin
192 /// ) -> Result<()> {
193 /// let response = client.create_database()
194 /// /* set fields */
195 /// .poller().until_done().await?;
196 /// println!("response {:?}", response);
197 /// Ok(())
198 /// }
199 /// ```
200 pub fn create_database(&self) -> super::builder::database_admin::CreateDatabase {
201 super::builder::database_admin::CreateDatabase::new(self.inner.clone())
202 }
203
204 /// Gets the state of a Cloud Spanner database.
205 ///
206 /// # Example
207 /// ```
208 /// # use google_cloud_spanner_admin_database_v1::client::DatabaseAdmin;
209 /// use google_cloud_spanner_admin_database_v1::Result;
210 /// async fn sample(
211 /// client: &DatabaseAdmin, project_id: &str, instance_id: &str, database_id: &str
212 /// ) -> Result<()> {
213 /// let response = client.get_database()
214 /// .set_name(format!("projects/{project_id}/instances/{instance_id}/databases/{database_id}"))
215 /// .send().await?;
216 /// println!("response {:?}", response);
217 /// Ok(())
218 /// }
219 /// ```
220 pub fn get_database(&self) -> super::builder::database_admin::GetDatabase {
221 super::builder::database_admin::GetDatabase::new(self.inner.clone())
222 }
223
224 /// Updates a Cloud Spanner database. The returned
225 /// [long-running operation][google.longrunning.Operation] can be used to track
226 /// the progress of updating the database. If the named database does not
227 /// exist, returns `NOT_FOUND`.
228 ///
229 /// While the operation is pending:
230 ///
231 /// * The database's
232 /// [reconciling][google.spanner.admin.database.v1.Database.reconciling]
233 /// field is set to true.
234 /// * Cancelling the operation is best-effort. If the cancellation succeeds,
235 /// the operation metadata's
236 /// [cancel_time][google.spanner.admin.database.v1.UpdateDatabaseMetadata.cancel_time]
237 /// is set, the updates are reverted, and the operation terminates with a
238 /// `CANCELLED` status.
239 /// * New UpdateDatabase requests will return a `FAILED_PRECONDITION` error
240 /// until the pending operation is done (returns successfully or with
241 /// error).
242 /// * Reading the database via the API continues to give the pre-request
243 /// values.
244 ///
245 /// Upon completion of the returned operation:
246 ///
247 /// * The new values are in effect and readable via the API.
248 /// * The database's
249 /// [reconciling][google.spanner.admin.database.v1.Database.reconciling]
250 /// field becomes false.
251 ///
252 /// The returned [long-running operation][google.longrunning.Operation] will
253 /// have a name of the format
254 /// `projects/<project>/instances/<instance>/databases/<database>/operations/<operation_id>`
255 /// and can be used to track the database modification. The
256 /// [metadata][google.longrunning.Operation.metadata] field type is
257 /// [UpdateDatabaseMetadata][google.spanner.admin.database.v1.UpdateDatabaseMetadata].
258 /// The [response][google.longrunning.Operation.response] field type is
259 /// [Database][google.spanner.admin.database.v1.Database], if successful.
260 ///
261 /// [google.longrunning.Operation]: google_cloud_longrunning::model::Operation
262 /// [google.longrunning.Operation.metadata]: google_cloud_longrunning::model::Operation::metadata
263 /// [google.longrunning.Operation.response]: google_cloud_longrunning::model::Operation::result
264 /// [google.spanner.admin.database.v1.Database]: crate::model::Database
265 /// [google.spanner.admin.database.v1.Database.reconciling]: crate::model::Database::reconciling
266 /// [google.spanner.admin.database.v1.UpdateDatabaseMetadata]: crate::model::UpdateDatabaseMetadata
267 /// [google.spanner.admin.database.v1.UpdateDatabaseMetadata.cancel_time]: crate::model::UpdateDatabaseMetadata::cancel_time
268 ///
269 /// # Long running operations
270 ///
271 /// This method is used to start, and/or poll a [long-running Operation].
272 /// The [Working with long-running operations] chapter in the [user guide]
273 /// covers these operations in detail.
274 ///
275 /// [long-running operation]: https://google.aip.dev/151
276 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
277 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
278 ///
279 /// # Example
280 /// ```
281 /// # use google_cloud_spanner_admin_database_v1::client::DatabaseAdmin;
282 /// use google_cloud_lro::Poller;
283 /// # extern crate wkt as google_cloud_wkt;
284 /// use google_cloud_wkt::FieldMask;
285 /// use google_cloud_spanner_admin_database_v1::model::Database;
286 /// use google_cloud_spanner_admin_database_v1::Result;
287 /// async fn sample(
288 /// client: &DatabaseAdmin, project_id: &str, instance_id: &str, database_id: &str
289 /// ) -> Result<()> {
290 /// let response = client.update_database()
291 /// .set_database(
292 /// Database::new().set_name(format!("projects/{project_id}/instances/{instance_id}/databases/{database_id}"))/* set fields */
293 /// )
294 /// .set_update_mask(FieldMask::default().set_paths(["updated.field.path1", "updated.field.path2"]))
295 /// .poller().until_done().await?;
296 /// println!("response {:?}", response);
297 /// Ok(())
298 /// }
299 /// ```
300 pub fn update_database(&self) -> super::builder::database_admin::UpdateDatabase {
301 super::builder::database_admin::UpdateDatabase::new(self.inner.clone())
302 }
303
304 /// Updates the schema of a Cloud Spanner database by
305 /// creating/altering/dropping tables, columns, indexes, etc. The returned
306 /// [long-running operation][google.longrunning.Operation] will have a name of
307 /// the format `<database_name>/operations/<operation_id>` and can be used to
308 /// track execution of the schema change(s). The
309 /// [metadata][google.longrunning.Operation.metadata] field type is
310 /// [UpdateDatabaseDdlMetadata][google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata].
311 /// The operation has no response.
312 ///
313 /// [google.longrunning.Operation]: google_cloud_longrunning::model::Operation
314 /// [google.longrunning.Operation.metadata]: google_cloud_longrunning::model::Operation::metadata
315 /// [google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata]: crate::model::UpdateDatabaseDdlMetadata
316 ///
317 /// # Long running operations
318 ///
319 /// This method is used to start, and/or poll a [long-running Operation].
320 /// The [Working with long-running operations] chapter in the [user guide]
321 /// covers these operations in detail.
322 ///
323 /// [long-running operation]: https://google.aip.dev/151
324 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
325 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
326 ///
327 /// # Example
328 /// ```
329 /// # use google_cloud_spanner_admin_database_v1::client::DatabaseAdmin;
330 /// use google_cloud_lro::Poller;
331 /// use google_cloud_spanner_admin_database_v1::Result;
332 /// async fn sample(
333 /// client: &DatabaseAdmin
334 /// ) -> Result<()> {
335 /// client.update_database_ddl()
336 /// /* set fields */
337 /// .poller().until_done().await?;
338 /// Ok(())
339 /// }
340 /// ```
341 pub fn update_database_ddl(&self) -> super::builder::database_admin::UpdateDatabaseDdl {
342 super::builder::database_admin::UpdateDatabaseDdl::new(self.inner.clone())
343 }
344
345 /// Drops (aka deletes) a Cloud Spanner database.
346 /// Completed backups for the database will be retained according to their
347 /// `expire_time`.
348 /// Note: Cloud Spanner might continue to accept requests for a few seconds
349 /// after the database has been deleted.
350 ///
351 /// # Example
352 /// ```
353 /// # use google_cloud_spanner_admin_database_v1::client::DatabaseAdmin;
354 /// use google_cloud_spanner_admin_database_v1::Result;
355 /// async fn sample(
356 /// client: &DatabaseAdmin
357 /// ) -> Result<()> {
358 /// client.drop_database()
359 /// /* set fields */
360 /// .send().await?;
361 /// Ok(())
362 /// }
363 /// ```
364 pub fn drop_database(&self) -> super::builder::database_admin::DropDatabase {
365 super::builder::database_admin::DropDatabase::new(self.inner.clone())
366 }
367
368 /// Returns the schema of a Cloud Spanner database as a list of formatted
369 /// DDL statements. This method does not show pending schema updates, those may
370 /// be queried using the [Operations][google.longrunning.Operations] API.
371 ///
372 /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
373 ///
374 /// # Example
375 /// ```
376 /// # use google_cloud_spanner_admin_database_v1::client::DatabaseAdmin;
377 /// use google_cloud_spanner_admin_database_v1::Result;
378 /// async fn sample(
379 /// client: &DatabaseAdmin
380 /// ) -> Result<()> {
381 /// let response = client.get_database_ddl()
382 /// /* set fields */
383 /// .send().await?;
384 /// println!("response {:?}", response);
385 /// Ok(())
386 /// }
387 /// ```
388 pub fn get_database_ddl(&self) -> super::builder::database_admin::GetDatabaseDdl {
389 super::builder::database_admin::GetDatabaseDdl::new(self.inner.clone())
390 }
391
392 /// Sets the access control policy on a database or backup resource.
393 /// Replaces any existing policy.
394 ///
395 /// Authorization requires `spanner.databases.setIamPolicy`
396 /// permission on [resource][google.iam.v1.SetIamPolicyRequest.resource].
397 /// For backups, authorization requires `spanner.backups.setIamPolicy`
398 /// permission on [resource][google.iam.v1.SetIamPolicyRequest.resource].
399 ///
400 /// [google.iam.v1.SetIamPolicyRequest.resource]: google_cloud_iam_v1::model::SetIamPolicyRequest::resource
401 ///
402 /// # Example
403 /// ```
404 /// # use google_cloud_spanner_admin_database_v1::client::DatabaseAdmin;
405 /// use google_cloud_spanner_admin_database_v1::Result;
406 /// async fn sample(
407 /// client: &DatabaseAdmin
408 /// ) -> Result<()> {
409 /// let response = client.set_iam_policy()
410 /// /* set fields */
411 /// .send().await?;
412 /// println!("response {:?}", response);
413 /// Ok(())
414 /// }
415 /// ```
416 pub fn set_iam_policy(&self) -> super::builder::database_admin::SetIamPolicy {
417 super::builder::database_admin::SetIamPolicy::new(self.inner.clone())
418 }
419
420 /// Gets the access control policy for a database or backup resource.
421 /// Returns an empty policy if a database or backup exists but does not have a
422 /// policy set.
423 ///
424 /// Authorization requires `spanner.databases.getIamPolicy` permission on
425 /// [resource][google.iam.v1.GetIamPolicyRequest.resource].
426 /// For backups, authorization requires `spanner.backups.getIamPolicy`
427 /// permission on [resource][google.iam.v1.GetIamPolicyRequest.resource].
428 ///
429 /// [google.iam.v1.GetIamPolicyRequest.resource]: google_cloud_iam_v1::model::GetIamPolicyRequest::resource
430 ///
431 /// # Example
432 /// ```
433 /// # use google_cloud_spanner_admin_database_v1::client::DatabaseAdmin;
434 /// use google_cloud_spanner_admin_database_v1::Result;
435 /// async fn sample(
436 /// client: &DatabaseAdmin
437 /// ) -> Result<()> {
438 /// let response = client.get_iam_policy()
439 /// /* set fields */
440 /// .send().await?;
441 /// println!("response {:?}", response);
442 /// Ok(())
443 /// }
444 /// ```
445 pub fn get_iam_policy(&self) -> super::builder::database_admin::GetIamPolicy {
446 super::builder::database_admin::GetIamPolicy::new(self.inner.clone())
447 }
448
449 /// Returns permissions that the caller has on the specified database or backup
450 /// resource.
451 ///
452 /// Attempting this RPC on a non-existent Cloud Spanner database will
453 /// result in a NOT_FOUND error if the user has
454 /// `spanner.databases.list` permission on the containing Cloud
455 /// Spanner instance. Otherwise returns an empty set of permissions.
456 /// Calling this method on a backup that does not exist will
457 /// result in a NOT_FOUND error if the user has
458 /// `spanner.backups.list` permission on the containing instance.
459 ///
460 /// # Example
461 /// ```
462 /// # use google_cloud_spanner_admin_database_v1::client::DatabaseAdmin;
463 /// use google_cloud_spanner_admin_database_v1::Result;
464 /// async fn sample(
465 /// client: &DatabaseAdmin
466 /// ) -> Result<()> {
467 /// let response = client.test_iam_permissions()
468 /// /* set fields */
469 /// .send().await?;
470 /// println!("response {:?}", response);
471 /// Ok(())
472 /// }
473 /// ```
474 pub fn test_iam_permissions(&self) -> super::builder::database_admin::TestIamPermissions {
475 super::builder::database_admin::TestIamPermissions::new(self.inner.clone())
476 }
477
478 /// Starts creating a new Cloud Spanner Backup.
479 /// The returned backup [long-running operation][google.longrunning.Operation]
480 /// will have a name of the format
481 /// `projects/<project>/instances/<instance>/backups/<backup>/operations/<operation_id>`
482 /// and can be used to track creation of the backup. The
483 /// [metadata][google.longrunning.Operation.metadata] field type is
484 /// [CreateBackupMetadata][google.spanner.admin.database.v1.CreateBackupMetadata].
485 /// The [response][google.longrunning.Operation.response] field type is
486 /// [Backup][google.spanner.admin.database.v1.Backup], if successful.
487 /// Cancelling the returned operation will stop the creation and delete the
488 /// backup. There can be only one pending backup creation per database. Backup
489 /// creation of different databases can run concurrently.
490 ///
491 /// [google.longrunning.Operation]: google_cloud_longrunning::model::Operation
492 /// [google.longrunning.Operation.metadata]: google_cloud_longrunning::model::Operation::metadata
493 /// [google.longrunning.Operation.response]: google_cloud_longrunning::model::Operation::result
494 /// [google.spanner.admin.database.v1.Backup]: crate::model::Backup
495 /// [google.spanner.admin.database.v1.CreateBackupMetadata]: crate::model::CreateBackupMetadata
496 ///
497 /// # Long running operations
498 ///
499 /// This method is used to start, and/or poll a [long-running Operation].
500 /// The [Working with long-running operations] chapter in the [user guide]
501 /// covers these operations in detail.
502 ///
503 /// [long-running operation]: https://google.aip.dev/151
504 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
505 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
506 ///
507 /// # Example
508 /// ```
509 /// # use google_cloud_spanner_admin_database_v1::client::DatabaseAdmin;
510 /// use google_cloud_lro::Poller;
511 /// use google_cloud_spanner_admin_database_v1::model::Backup;
512 /// use google_cloud_spanner_admin_database_v1::Result;
513 /// async fn sample(
514 /// client: &DatabaseAdmin, parent: &str
515 /// ) -> Result<()> {
516 /// let response = client.create_backup()
517 /// .set_parent(parent)
518 /// .set_backup_id("backup_id_value")
519 /// .set_backup(
520 /// Backup::new()/* set fields */
521 /// )
522 /// .poller().until_done().await?;
523 /// println!("response {:?}", response);
524 /// Ok(())
525 /// }
526 /// ```
527 pub fn create_backup(&self) -> super::builder::database_admin::CreateBackup {
528 super::builder::database_admin::CreateBackup::new(self.inner.clone())
529 }
530
531 /// Starts copying a Cloud Spanner Backup.
532 /// The returned backup [long-running operation][google.longrunning.Operation]
533 /// will have a name of the format
534 /// `projects/<project>/instances/<instance>/backups/<backup>/operations/<operation_id>`
535 /// and can be used to track copying of the backup. The operation is associated
536 /// with the destination backup.
537 /// The [metadata][google.longrunning.Operation.metadata] field type is
538 /// [CopyBackupMetadata][google.spanner.admin.database.v1.CopyBackupMetadata].
539 /// The [response][google.longrunning.Operation.response] field type is
540 /// [Backup][google.spanner.admin.database.v1.Backup], if successful.
541 /// Cancelling the returned operation will stop the copying and delete the
542 /// destination backup. Concurrent CopyBackup requests can run on the same
543 /// source backup.
544 ///
545 /// [google.longrunning.Operation]: google_cloud_longrunning::model::Operation
546 /// [google.longrunning.Operation.metadata]: google_cloud_longrunning::model::Operation::metadata
547 /// [google.longrunning.Operation.response]: google_cloud_longrunning::model::Operation::result
548 /// [google.spanner.admin.database.v1.Backup]: crate::model::Backup
549 /// [google.spanner.admin.database.v1.CopyBackupMetadata]: crate::model::CopyBackupMetadata
550 ///
551 /// # Long running operations
552 ///
553 /// This method is used to start, and/or poll a [long-running Operation].
554 /// The [Working with long-running operations] chapter in the [user guide]
555 /// covers these operations in detail.
556 ///
557 /// [long-running operation]: https://google.aip.dev/151
558 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
559 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
560 ///
561 /// # Example
562 /// ```
563 /// # use google_cloud_spanner_admin_database_v1::client::DatabaseAdmin;
564 /// use google_cloud_lro::Poller;
565 /// use google_cloud_spanner_admin_database_v1::Result;
566 /// async fn sample(
567 /// client: &DatabaseAdmin
568 /// ) -> Result<()> {
569 /// let response = client.copy_backup()
570 /// /* set fields */
571 /// .poller().until_done().await?;
572 /// println!("response {:?}", response);
573 /// Ok(())
574 /// }
575 /// ```
576 pub fn copy_backup(&self) -> super::builder::database_admin::CopyBackup {
577 super::builder::database_admin::CopyBackup::new(self.inner.clone())
578 }
579
580 /// Gets metadata on a pending or completed
581 /// [Backup][google.spanner.admin.database.v1.Backup].
582 ///
583 /// [google.spanner.admin.database.v1.Backup]: crate::model::Backup
584 ///
585 /// # Example
586 /// ```
587 /// # use google_cloud_spanner_admin_database_v1::client::DatabaseAdmin;
588 /// use google_cloud_spanner_admin_database_v1::Result;
589 /// async fn sample(
590 /// client: &DatabaseAdmin, project_id: &str, instance_id: &str, backup_id: &str
591 /// ) -> Result<()> {
592 /// let response = client.get_backup()
593 /// .set_name(format!("projects/{project_id}/instances/{instance_id}/backups/{backup_id}"))
594 /// .send().await?;
595 /// println!("response {:?}", response);
596 /// Ok(())
597 /// }
598 /// ```
599 pub fn get_backup(&self) -> super::builder::database_admin::GetBackup {
600 super::builder::database_admin::GetBackup::new(self.inner.clone())
601 }
602
603 /// Updates a pending or completed
604 /// [Backup][google.spanner.admin.database.v1.Backup].
605 ///
606 /// [google.spanner.admin.database.v1.Backup]: crate::model::Backup
607 ///
608 /// # Example
609 /// ```
610 /// # use google_cloud_spanner_admin_database_v1::client::DatabaseAdmin;
611 /// # extern crate wkt as google_cloud_wkt;
612 /// use google_cloud_wkt::FieldMask;
613 /// use google_cloud_spanner_admin_database_v1::model::Backup;
614 /// use google_cloud_spanner_admin_database_v1::Result;
615 /// async fn sample(
616 /// client: &DatabaseAdmin, project_id: &str, instance_id: &str, backup_id: &str
617 /// ) -> Result<()> {
618 /// let response = client.update_backup()
619 /// .set_backup(
620 /// Backup::new().set_name(format!("projects/{project_id}/instances/{instance_id}/backups/{backup_id}"))/* set fields */
621 /// )
622 /// .set_update_mask(FieldMask::default().set_paths(["updated.field.path1", "updated.field.path2"]))
623 /// .send().await?;
624 /// println!("response {:?}", response);
625 /// Ok(())
626 /// }
627 /// ```
628 pub fn update_backup(&self) -> super::builder::database_admin::UpdateBackup {
629 super::builder::database_admin::UpdateBackup::new(self.inner.clone())
630 }
631
632 /// Deletes a pending or completed
633 /// [Backup][google.spanner.admin.database.v1.Backup].
634 ///
635 /// [google.spanner.admin.database.v1.Backup]: crate::model::Backup
636 ///
637 /// # Example
638 /// ```
639 /// # use google_cloud_spanner_admin_database_v1::client::DatabaseAdmin;
640 /// use google_cloud_spanner_admin_database_v1::Result;
641 /// async fn sample(
642 /// client: &DatabaseAdmin, project_id: &str, instance_id: &str, backup_id: &str
643 /// ) -> Result<()> {
644 /// client.delete_backup()
645 /// .set_name(format!("projects/{project_id}/instances/{instance_id}/backups/{backup_id}"))
646 /// .send().await?;
647 /// Ok(())
648 /// }
649 /// ```
650 pub fn delete_backup(&self) -> super::builder::database_admin::DeleteBackup {
651 super::builder::database_admin::DeleteBackup::new(self.inner.clone())
652 }
653
654 /// Lists completed and pending backups.
655 /// Backups returned are ordered by `create_time` in descending order,
656 /// starting from the most recent `create_time`.
657 ///
658 /// # Example
659 /// ```
660 /// # use google_cloud_spanner_admin_database_v1::client::DatabaseAdmin;
661 /// use google_cloud_gax::paginator::ItemPaginator as _;
662 /// use google_cloud_spanner_admin_database_v1::Result;
663 /// async fn sample(
664 /// client: &DatabaseAdmin, parent: &str
665 /// ) -> Result<()> {
666 /// let mut list = client.list_backups()
667 /// .set_parent(parent)
668 /// .by_item();
669 /// while let Some(item) = list.next().await.transpose()? {
670 /// println!("{:?}", item);
671 /// }
672 /// Ok(())
673 /// }
674 /// ```
675 pub fn list_backups(&self) -> super::builder::database_admin::ListBackups {
676 super::builder::database_admin::ListBackups::new(self.inner.clone())
677 }
678
679 /// Create a new database by restoring from a completed backup. The new
680 /// database must be in the same project and in an instance with the same
681 /// instance configuration as the instance containing
682 /// the backup. The returned database [long-running
683 /// operation][google.longrunning.Operation] has a name of the format
684 /// `projects/<project>/instances/<instance>/databases/<database>/operations/<operation_id>`,
685 /// and can be used to track the progress of the operation, and to cancel it.
686 /// The [metadata][google.longrunning.Operation.metadata] field type is
687 /// [RestoreDatabaseMetadata][google.spanner.admin.database.v1.RestoreDatabaseMetadata].
688 /// The [response][google.longrunning.Operation.response] type
689 /// is [Database][google.spanner.admin.database.v1.Database], if
690 /// successful. Cancelling the returned operation will stop the restore and
691 /// delete the database.
692 /// There can be only one database being restored into an instance at a time.
693 /// Once the restore operation completes, a new restore operation can be
694 /// initiated, without waiting for the optimize operation associated with the
695 /// first restore to complete.
696 ///
697 /// [google.longrunning.Operation]: google_cloud_longrunning::model::Operation
698 /// [google.longrunning.Operation.metadata]: google_cloud_longrunning::model::Operation::metadata
699 /// [google.longrunning.Operation.response]: google_cloud_longrunning::model::Operation::result
700 /// [google.spanner.admin.database.v1.Database]: crate::model::Database
701 /// [google.spanner.admin.database.v1.RestoreDatabaseMetadata]: crate::model::RestoreDatabaseMetadata
702 ///
703 /// # Long running operations
704 ///
705 /// This method is used to start, and/or poll a [long-running Operation].
706 /// The [Working with long-running operations] chapter in the [user guide]
707 /// covers these operations in detail.
708 ///
709 /// [long-running operation]: https://google.aip.dev/151
710 /// [user guide]: https://googleapis.github.io/google-cloud-rust/
711 /// [working with long-running operations]: https://googleapis.github.io/google-cloud-rust/working_with_long_running_operations.html
712 ///
713 /// # Example
714 /// ```
715 /// # use google_cloud_spanner_admin_database_v1::client::DatabaseAdmin;
716 /// use google_cloud_lro::Poller;
717 /// use google_cloud_spanner_admin_database_v1::Result;
718 /// async fn sample(
719 /// client: &DatabaseAdmin
720 /// ) -> Result<()> {
721 /// let response = client.restore_database()
722 /// /* set fields */
723 /// .poller().until_done().await?;
724 /// println!("response {:?}", response);
725 /// Ok(())
726 /// }
727 /// ```
728 pub fn restore_database(&self) -> super::builder::database_admin::RestoreDatabase {
729 super::builder::database_admin::RestoreDatabase::new(self.inner.clone())
730 }
731
732 /// Lists database [longrunning-operations][google.longrunning.Operation].
733 /// A database operation has a name of the form
734 /// `projects/<project>/instances/<instance>/databases/<database>/operations/<operation>`.
735 /// The long-running operation
736 /// [metadata][google.longrunning.Operation.metadata] field type
737 /// `metadata.type_url` describes the type of the metadata. Operations returned
738 /// include those that have completed/failed/canceled within the last 7 days,
739 /// and pending operations.
740 ///
741 /// [google.longrunning.Operation]: google_cloud_longrunning::model::Operation
742 /// [google.longrunning.Operation.metadata]: google_cloud_longrunning::model::Operation::metadata
743 ///
744 /// # Example
745 /// ```
746 /// # use google_cloud_spanner_admin_database_v1::client::DatabaseAdmin;
747 /// use google_cloud_gax::paginator::ItemPaginator as _;
748 /// use google_cloud_spanner_admin_database_v1::Result;
749 /// async fn sample(
750 /// client: &DatabaseAdmin
751 /// ) -> Result<()> {
752 /// let mut list = client.list_database_operations()
753 /// /* set fields */
754 /// .by_item();
755 /// while let Some(item) = list.next().await.transpose()? {
756 /// println!("{:?}", item);
757 /// }
758 /// Ok(())
759 /// }
760 /// ```
761 pub fn list_database_operations(
762 &self,
763 ) -> super::builder::database_admin::ListDatabaseOperations {
764 super::builder::database_admin::ListDatabaseOperations::new(self.inner.clone())
765 }
766
767 /// Lists the backup [long-running operations][google.longrunning.Operation] in
768 /// the given instance. A backup operation has a name of the form
769 /// `projects/<project>/instances/<instance>/backups/<backup>/operations/<operation>`.
770 /// The long-running operation
771 /// [metadata][google.longrunning.Operation.metadata] field type
772 /// `metadata.type_url` describes the type of the metadata. Operations returned
773 /// include those that have completed/failed/canceled within the last 7 days,
774 /// and pending operations. Operations returned are ordered by
775 /// `operation.metadata.value.progress.start_time` in descending order starting
776 /// from the most recently started operation.
777 ///
778 /// [google.longrunning.Operation]: google_cloud_longrunning::model::Operation
779 /// [google.longrunning.Operation.metadata]: google_cloud_longrunning::model::Operation::metadata
780 ///
781 /// # Example
782 /// ```
783 /// # use google_cloud_spanner_admin_database_v1::client::DatabaseAdmin;
784 /// use google_cloud_gax::paginator::ItemPaginator as _;
785 /// use google_cloud_spanner_admin_database_v1::Result;
786 /// async fn sample(
787 /// client: &DatabaseAdmin
788 /// ) -> Result<()> {
789 /// let mut list = client.list_backup_operations()
790 /// /* set fields */
791 /// .by_item();
792 /// while let Some(item) = list.next().await.transpose()? {
793 /// println!("{:?}", item);
794 /// }
795 /// Ok(())
796 /// }
797 /// ```
798 pub fn list_backup_operations(&self) -> super::builder::database_admin::ListBackupOperations {
799 super::builder::database_admin::ListBackupOperations::new(self.inner.clone())
800 }
801
802 /// Lists Cloud Spanner database roles.
803 ///
804 /// # Example
805 /// ```
806 /// # use google_cloud_spanner_admin_database_v1::client::DatabaseAdmin;
807 /// use google_cloud_gax::paginator::ItemPaginator as _;
808 /// use google_cloud_spanner_admin_database_v1::Result;
809 /// async fn sample(
810 /// client: &DatabaseAdmin, project_id: &str, instance_id: &str, database_id: &str
811 /// ) -> Result<()> {
812 /// let mut list = client.list_database_roles()
813 /// .set_parent(format!("projects/{project_id}/instances/{instance_id}/databases/{database_id}"))
814 /// .by_item();
815 /// while let Some(item) = list.next().await.transpose()? {
816 /// println!("{:?}", item);
817 /// }
818 /// Ok(())
819 /// }
820 /// ```
821 pub fn list_database_roles(&self) -> super::builder::database_admin::ListDatabaseRoles {
822 super::builder::database_admin::ListDatabaseRoles::new(self.inner.clone())
823 }
824
825 /// Adds split points to specified tables, indexes of a database.
826 ///
827 /// # Example
828 /// ```
829 /// # use google_cloud_spanner_admin_database_v1::client::DatabaseAdmin;
830 /// use google_cloud_spanner_admin_database_v1::Result;
831 /// async fn sample(
832 /// client: &DatabaseAdmin
833 /// ) -> Result<()> {
834 /// let response = client.add_split_points()
835 /// /* set fields */
836 /// .send().await?;
837 /// println!("response {:?}", response);
838 /// Ok(())
839 /// }
840 /// ```
841 pub fn add_split_points(&self) -> super::builder::database_admin::AddSplitPoints {
842 super::builder::database_admin::AddSplitPoints::new(self.inner.clone())
843 }
844
845 /// Creates a new backup schedule.
846 ///
847 /// # Example
848 /// ```
849 /// # use google_cloud_spanner_admin_database_v1::client::DatabaseAdmin;
850 /// use google_cloud_spanner_admin_database_v1::model::BackupSchedule;
851 /// use google_cloud_spanner_admin_database_v1::Result;
852 /// async fn sample(
853 /// client: &DatabaseAdmin, project_id: &str, instance_id: &str, database_id: &str
854 /// ) -> Result<()> {
855 /// let response = client.create_backup_schedule()
856 /// .set_parent(format!("projects/{project_id}/instances/{instance_id}/databases/{database_id}"))
857 /// .set_backup_schedule(
858 /// BackupSchedule::new()/* set fields */
859 /// )
860 /// .send().await?;
861 /// println!("response {:?}", response);
862 /// Ok(())
863 /// }
864 /// ```
865 pub fn create_backup_schedule(&self) -> super::builder::database_admin::CreateBackupSchedule {
866 super::builder::database_admin::CreateBackupSchedule::new(self.inner.clone())
867 }
868
869 /// Gets backup schedule for the input schedule name.
870 ///
871 /// # Example
872 /// ```
873 /// # use google_cloud_spanner_admin_database_v1::client::DatabaseAdmin;
874 /// use google_cloud_spanner_admin_database_v1::Result;
875 /// async fn sample(
876 /// client: &DatabaseAdmin, project_id: &str, instance_id: &str, database_id: &str, schedule_id: &str
877 /// ) -> Result<()> {
878 /// let response = client.get_backup_schedule()
879 /// .set_name(format!("projects/{project_id}/instances/{instance_id}/databases/{database_id}/backupSchedules/{schedule_id}"))
880 /// .send().await?;
881 /// println!("response {:?}", response);
882 /// Ok(())
883 /// }
884 /// ```
885 pub fn get_backup_schedule(&self) -> super::builder::database_admin::GetBackupSchedule {
886 super::builder::database_admin::GetBackupSchedule::new(self.inner.clone())
887 }
888
889 /// Updates a backup schedule.
890 ///
891 /// # Example
892 /// ```
893 /// # use google_cloud_spanner_admin_database_v1::client::DatabaseAdmin;
894 /// # extern crate wkt as google_cloud_wkt;
895 /// use google_cloud_wkt::FieldMask;
896 /// use google_cloud_spanner_admin_database_v1::model::BackupSchedule;
897 /// use google_cloud_spanner_admin_database_v1::Result;
898 /// async fn sample(
899 /// client: &DatabaseAdmin, project_id: &str, instance_id: &str, database_id: &str, schedule_id: &str
900 /// ) -> Result<()> {
901 /// let response = client.update_backup_schedule()
902 /// .set_backup_schedule(
903 /// BackupSchedule::new().set_name(format!("projects/{project_id}/instances/{instance_id}/databases/{database_id}/backupSchedules/{schedule_id}"))/* set fields */
904 /// )
905 /// .set_update_mask(FieldMask::default().set_paths(["updated.field.path1", "updated.field.path2"]))
906 /// .send().await?;
907 /// println!("response {:?}", response);
908 /// Ok(())
909 /// }
910 /// ```
911 pub fn update_backup_schedule(&self) -> super::builder::database_admin::UpdateBackupSchedule {
912 super::builder::database_admin::UpdateBackupSchedule::new(self.inner.clone())
913 }
914
915 /// Deletes a backup schedule.
916 ///
917 /// # Example
918 /// ```
919 /// # use google_cloud_spanner_admin_database_v1::client::DatabaseAdmin;
920 /// use google_cloud_spanner_admin_database_v1::Result;
921 /// async fn sample(
922 /// client: &DatabaseAdmin, project_id: &str, instance_id: &str, database_id: &str, schedule_id: &str
923 /// ) -> Result<()> {
924 /// client.delete_backup_schedule()
925 /// .set_name(format!("projects/{project_id}/instances/{instance_id}/databases/{database_id}/backupSchedules/{schedule_id}"))
926 /// .send().await?;
927 /// Ok(())
928 /// }
929 /// ```
930 pub fn delete_backup_schedule(&self) -> super::builder::database_admin::DeleteBackupSchedule {
931 super::builder::database_admin::DeleteBackupSchedule::new(self.inner.clone())
932 }
933
934 /// Lists all the backup schedules for the database.
935 ///
936 /// # Example
937 /// ```
938 /// # use google_cloud_spanner_admin_database_v1::client::DatabaseAdmin;
939 /// use google_cloud_gax::paginator::ItemPaginator as _;
940 /// use google_cloud_spanner_admin_database_v1::Result;
941 /// async fn sample(
942 /// client: &DatabaseAdmin, project_id: &str, instance_id: &str, database_id: &str
943 /// ) -> Result<()> {
944 /// let mut list = client.list_backup_schedules()
945 /// .set_parent(format!("projects/{project_id}/instances/{instance_id}/databases/{database_id}"))
946 /// .by_item();
947 /// while let Some(item) = list.next().await.transpose()? {
948 /// println!("{:?}", item);
949 /// }
950 /// Ok(())
951 /// }
952 /// ```
953 pub fn list_backup_schedules(&self) -> super::builder::database_admin::ListBackupSchedules {
954 super::builder::database_admin::ListBackupSchedules::new(self.inner.clone())
955 }
956
957 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
958 ///
959 /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
960 ///
961 /// # Example
962 /// ```
963 /// # use google_cloud_spanner_admin_database_v1::client::DatabaseAdmin;
964 /// use google_cloud_gax::paginator::ItemPaginator as _;
965 /// use google_cloud_spanner_admin_database_v1::Result;
966 /// async fn sample(
967 /// client: &DatabaseAdmin
968 /// ) -> Result<()> {
969 /// let mut list = client.list_operations()
970 /// /* set fields */
971 /// .by_item();
972 /// while let Some(item) = list.next().await.transpose()? {
973 /// println!("{:?}", item);
974 /// }
975 /// Ok(())
976 /// }
977 /// ```
978 pub fn list_operations(&self) -> super::builder::database_admin::ListOperations {
979 super::builder::database_admin::ListOperations::new(self.inner.clone())
980 }
981
982 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
983 ///
984 /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
985 ///
986 /// # Example
987 /// ```
988 /// # use google_cloud_spanner_admin_database_v1::client::DatabaseAdmin;
989 /// use google_cloud_spanner_admin_database_v1::Result;
990 /// async fn sample(
991 /// client: &DatabaseAdmin
992 /// ) -> Result<()> {
993 /// let response = client.get_operation()
994 /// /* set fields */
995 /// .send().await?;
996 /// println!("response {:?}", response);
997 /// Ok(())
998 /// }
999 /// ```
1000 pub fn get_operation(&self) -> super::builder::database_admin::GetOperation {
1001 super::builder::database_admin::GetOperation::new(self.inner.clone())
1002 }
1003
1004 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
1005 ///
1006 /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
1007 ///
1008 /// # Example
1009 /// ```
1010 /// # use google_cloud_spanner_admin_database_v1::client::DatabaseAdmin;
1011 /// use google_cloud_spanner_admin_database_v1::Result;
1012 /// async fn sample(
1013 /// client: &DatabaseAdmin
1014 /// ) -> Result<()> {
1015 /// client.delete_operation()
1016 /// /* set fields */
1017 /// .send().await?;
1018 /// Ok(())
1019 /// }
1020 /// ```
1021 pub fn delete_operation(&self) -> super::builder::database_admin::DeleteOperation {
1022 super::builder::database_admin::DeleteOperation::new(self.inner.clone())
1023 }
1024
1025 /// Provides the [Operations][google.longrunning.Operations] service functionality in this service.
1026 ///
1027 /// [google.longrunning.Operations]: google-cloud-longrunning::client::Operations
1028 ///
1029 /// # Example
1030 /// ```
1031 /// # use google_cloud_spanner_admin_database_v1::client::DatabaseAdmin;
1032 /// use google_cloud_spanner_admin_database_v1::Result;
1033 /// async fn sample(
1034 /// client: &DatabaseAdmin
1035 /// ) -> Result<()> {
1036 /// client.cancel_operation()
1037 /// /* set fields */
1038 /// .send().await?;
1039 /// Ok(())
1040 /// }
1041 /// ```
1042 pub fn cancel_operation(&self) -> super::builder::database_admin::CancelOperation {
1043 super::builder::database_admin::CancelOperation::new(self.inner.clone())
1044 }
1045}