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