package database
import "cloud.google.com/go/spanner/admin/database/apiv1"
Copyright 2020 Google LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Package database is an auto-generated package for the Cloud Spanner API.
Cloud Spanner is a managed, mission-critical, globally consistent and scalable relational database service.
General documentation
For information that is relevant for all client libraries please reference https://pkg.go.dev/cloud.google.com/go#pkg-overview. Some information on this page includes:
- Authentication and Authorization
- Timeouts and Cancellation
- Testing against Client Libraries
- Debugging Client Libraries
- Inspecting errors
Example usage
To get started with this package, create a client.
// go get cloud.google.com/go/spanner/admin/database/apiv1@latest ctx := context.Background() // This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in: // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options c, err := database.NewDatabaseAdminClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close()
The client will use your default application credentials. Clients should be reused instead of created as needed. The methods of Client are safe for concurrent use by multiple goroutines. The returned client must be Closed when it is done being used.
Using the Client
The following is an example of making an API call with the newly created client, mentioned above.
req := &databasepb.AddSplitPointsRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/cloud.google.com/go/spanner/admin/database/apiv1/databasepb#AddSplitPointsRequest. } resp, err := c.AddSplitPoints(ctx, req) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp
Use of Context
The ctx passed to NewDatabaseAdminClient is used for authentication requests and for creating the underlying connection, but is not used for subsequent calls. Individual methods on the client use the ctx given to them.
To close the open connection, use the Close() method.
Copyright 2020 Google LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- func DatabaseAdminDatabasePath(project, instance, database string) string
- func DatabaseAdminInstancePath(project, instance string) string
- func DefaultAuthScopes() []string
- type BackupIterator
- func (it *BackupIterator) All() iter.Seq2[*databasepb.Backup, error]
- func (it *BackupIterator) Next() (*databasepb.Backup, error)
- func (it *BackupIterator) PageInfo() *iterator.PageInfo
- type BackupScheduleIterator
- func (it *BackupScheduleIterator) All() iter.Seq2[*databasepb.BackupSchedule, error]
- func (it *BackupScheduleIterator) Next() (*databasepb.BackupSchedule, error)
- func (it *BackupScheduleIterator) PageInfo() *iterator.PageInfo
- type CopyBackupOperation
- func (op *CopyBackupOperation) Done() bool
- func (op *CopyBackupOperation) Metadata() (*databasepb.CopyBackupMetadata, error)
- func (op *CopyBackupOperation) Name() string
- func (op *CopyBackupOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*databasepb.Backup, error)
- func (op *CopyBackupOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*databasepb.Backup, error)
- type CreateBackupOperation
- func (op *CreateBackupOperation) Done() bool
- func (op *CreateBackupOperation) Metadata() (*databasepb.CreateBackupMetadata, error)
- func (op *CreateBackupOperation) Name() string
- func (op *CreateBackupOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*databasepb.Backup, error)
- func (op *CreateBackupOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*databasepb.Backup, error)
- type CreateDatabaseOperation
- func (op *CreateDatabaseOperation) Done() bool
- func (op *CreateDatabaseOperation) Metadata() (*databasepb.CreateDatabaseMetadata, error)
- func (op *CreateDatabaseOperation) Name() string
- func (op *CreateDatabaseOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*databasepb.Database, error)
- func (op *CreateDatabaseOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*databasepb.Database, error)
- type DatabaseAdminCallOptions
- type DatabaseAdminClient
- func NewDatabaseAdminClient(ctx context.Context, opts ...option.ClientOption) (*DatabaseAdminClient, error)
- func NewDatabaseAdminRESTClient(ctx context.Context, opts ...option.ClientOption) (*DatabaseAdminClient, error)
- func (c *DatabaseAdminClient) AddSplitPoints(ctx context.Context, req *databasepb.AddSplitPointsRequest, opts ...gax.CallOption) (*databasepb.AddSplitPointsResponse, error)
- func (c *DatabaseAdminClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error
- func (c *DatabaseAdminClient) Close() error
- func (c *DatabaseAdminClient) Connection() *grpc.ClientConn
- func (c *DatabaseAdminClient) CopyBackup(ctx context.Context, req *databasepb.CopyBackupRequest, opts ...gax.CallOption) (*CopyBackupOperation, error)
- func (c *DatabaseAdminClient) CopyBackupOperation(name string) *CopyBackupOperation
- func (c *DatabaseAdminClient) CreateBackup(ctx context.Context, req *databasepb.CreateBackupRequest, opts ...gax.CallOption) (*CreateBackupOperation, error)
- func (c *DatabaseAdminClient) CreateBackupOperation(name string) *CreateBackupOperation
- func (c *DatabaseAdminClient) CreateBackupSchedule(ctx context.Context, req *databasepb.CreateBackupScheduleRequest, opts ...gax.CallOption) (*databasepb.BackupSchedule, error)
- func (c *DatabaseAdminClient) CreateDatabase(ctx context.Context, req *databasepb.CreateDatabaseRequest, opts ...gax.CallOption) (*CreateDatabaseOperation, error)
- func (c *DatabaseAdminClient) CreateDatabaseOperation(name string) *CreateDatabaseOperation
- func (c *DatabaseAdminClient) CreateDatabaseWithRetry(ctx context.Context, req *databasepb.CreateDatabaseRequest, opts ...gax.CallOption) (*CreateDatabaseOperation, error)
- func (c *DatabaseAdminClient) DeleteBackup(ctx context.Context, req *databasepb.DeleteBackupRequest, opts ...gax.CallOption) error
- func (c *DatabaseAdminClient) DeleteBackupSchedule(ctx context.Context, req *databasepb.DeleteBackupScheduleRequest, opts ...gax.CallOption) error
- func (c *DatabaseAdminClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error
- func (c *DatabaseAdminClient) DropDatabase(ctx context.Context, req *databasepb.DropDatabaseRequest, opts ...gax.CallOption) error
- func (c *DatabaseAdminClient) GetBackup(ctx context.Context, req *databasepb.GetBackupRequest, opts ...gax.CallOption) (*databasepb.Backup, error)
- func (c *DatabaseAdminClient) GetBackupSchedule(ctx context.Context, req *databasepb.GetBackupScheduleRequest, opts ...gax.CallOption) (*databasepb.BackupSchedule, error)
- func (c *DatabaseAdminClient) GetDatabase(ctx context.Context, req *databasepb.GetDatabaseRequest, opts ...gax.CallOption) (*databasepb.Database, error)
- func (c *DatabaseAdminClient) GetDatabaseDdl(ctx context.Context, req *databasepb.GetDatabaseDdlRequest, opts ...gax.CallOption) (*databasepb.GetDatabaseDdlResponse, error)
- func (c *DatabaseAdminClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error)
- func (c *DatabaseAdminClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error)
- func (c *DatabaseAdminClient) ListBackupOperations(ctx context.Context, req *databasepb.ListBackupOperationsRequest, opts ...gax.CallOption) *OperationIterator
- func (c *DatabaseAdminClient) ListBackupSchedules(ctx context.Context, req *databasepb.ListBackupSchedulesRequest, opts ...gax.CallOption) *BackupScheduleIterator
- func (c *DatabaseAdminClient) ListBackups(ctx context.Context, req *databasepb.ListBackupsRequest, opts ...gax.CallOption) *BackupIterator
- func (c *DatabaseAdminClient) ListDatabaseOperations(ctx context.Context, req *databasepb.ListDatabaseOperationsRequest, opts ...gax.CallOption) *OperationIterator
- func (c *DatabaseAdminClient) ListDatabaseRoles(ctx context.Context, req *databasepb.ListDatabaseRolesRequest, opts ...gax.CallOption) *DatabaseRoleIterator
- func (c *DatabaseAdminClient) ListDatabases(ctx context.Context, req *databasepb.ListDatabasesRequest, opts ...gax.CallOption) *DatabaseIterator
- func (c *DatabaseAdminClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator
- func (c *DatabaseAdminClient) RestoreDatabase(ctx context.Context, req *databasepb.RestoreDatabaseRequest, opts ...gax.CallOption) (*RestoreDatabaseOperation, error)
- func (c *DatabaseAdminClient) RestoreDatabaseOperation(name string) *RestoreDatabaseOperation
- func (c *DatabaseAdminClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error)
- func (c *DatabaseAdminClient) StartBackupOperation(ctx context.Context, backupID string, databasePath string, expireTime time.Time, opts ...gax.CallOption) (*CreateBackupOperation, error)
- func (c *DatabaseAdminClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error)
- func (c *DatabaseAdminClient) UpdateBackup(ctx context.Context, req *databasepb.UpdateBackupRequest, opts ...gax.CallOption) (*databasepb.Backup, error)
- func (c *DatabaseAdminClient) UpdateBackupSchedule(ctx context.Context, req *databasepb.UpdateBackupScheduleRequest, opts ...gax.CallOption) (*databasepb.BackupSchedule, error)
- func (c *DatabaseAdminClient) UpdateDatabase(ctx context.Context, req *databasepb.UpdateDatabaseRequest, opts ...gax.CallOption) (*UpdateDatabaseOperation, error)
- func (c *DatabaseAdminClient) UpdateDatabaseDdl(ctx context.Context, req *databasepb.UpdateDatabaseDdlRequest, opts ...gax.CallOption) (*UpdateDatabaseDdlOperation, error)
- func (c *DatabaseAdminClient) UpdateDatabaseDdlOperation(name string) *UpdateDatabaseDdlOperation
- func (c *DatabaseAdminClient) UpdateDatabaseOperation(name string) *UpdateDatabaseOperation
- type DatabaseIterator
- func (it *DatabaseIterator) All() iter.Seq2[*databasepb.Database, error]
- func (it *DatabaseIterator) Next() (*databasepb.Database, error)
- func (it *DatabaseIterator) PageInfo() *iterator.PageInfo
- type DatabaseRoleIterator
- func (it *DatabaseRoleIterator) All() iter.Seq2[*databasepb.DatabaseRole, error]
- func (it *DatabaseRoleIterator) Next() (*databasepb.DatabaseRole, error)
- func (it *DatabaseRoleIterator) PageInfo() *iterator.PageInfo
- type OperationIterator
- func (it *OperationIterator) All() iter.Seq2[*longrunningpb.Operation, error]
- func (it *OperationIterator) Next() (*longrunningpb.Operation, error)
- func (it *OperationIterator) PageInfo() *iterator.PageInfo
- type RestoreDatabaseOperation
- func (op *RestoreDatabaseOperation) Done() bool
- func (op *RestoreDatabaseOperation) Metadata() (*databasepb.RestoreDatabaseMetadata, error)
- func (op *RestoreDatabaseOperation) Name() string
- func (op *RestoreDatabaseOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*databasepb.Database, error)
- func (op *RestoreDatabaseOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*databasepb.Database, error)
- type UpdateDatabaseDdlOperation
- func (op *UpdateDatabaseDdlOperation) Done() bool
- func (op *UpdateDatabaseDdlOperation) Metadata() (*databasepb.UpdateDatabaseDdlMetadata, error)
- func (op *UpdateDatabaseDdlOperation) Name() string
- func (op *UpdateDatabaseDdlOperation) Poll(ctx context.Context, opts ...gax.CallOption) error
- func (op *UpdateDatabaseDdlOperation) Wait(ctx context.Context, opts ...gax.CallOption) error
- type UpdateDatabaseOperation
- func (op *UpdateDatabaseOperation) Done() bool
- func (op *UpdateDatabaseOperation) Metadata() (*databasepb.UpdateDatabaseMetadata, error)
- func (op *UpdateDatabaseOperation) Name() string
- func (op *UpdateDatabaseOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*databasepb.Database, error)
- func (op *UpdateDatabaseOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*databasepb.Database, error)
Examples ¶
- DatabaseAdminClient.AddSplitPoints
- DatabaseAdminClient.CancelOperation
- DatabaseAdminClient.CopyBackup
- DatabaseAdminClient.CreateBackup
- DatabaseAdminClient.CreateBackupSchedule
- DatabaseAdminClient.CreateDatabase
- DatabaseAdminClient.DeleteBackup
- DatabaseAdminClient.DeleteBackupSchedule
- DatabaseAdminClient.DeleteOperation
- DatabaseAdminClient.DropDatabase
- DatabaseAdminClient.GetBackup
- DatabaseAdminClient.GetBackupSchedule
- DatabaseAdminClient.GetDatabase
- DatabaseAdminClient.GetDatabaseDdl
- DatabaseAdminClient.GetIamPolicy
- DatabaseAdminClient.GetOperation
- DatabaseAdminClient.ListBackupOperations
- DatabaseAdminClient.ListBackupOperations (All)
- DatabaseAdminClient.ListBackupSchedules
- DatabaseAdminClient.ListBackupSchedules (All)
- DatabaseAdminClient.ListBackups
- DatabaseAdminClient.ListBackups (All)
- DatabaseAdminClient.ListDatabaseOperations
- DatabaseAdminClient.ListDatabaseOperations (All)
- DatabaseAdminClient.ListDatabaseRoles
- DatabaseAdminClient.ListDatabaseRoles (All)
- DatabaseAdminClient.ListDatabases
- DatabaseAdminClient.ListDatabases (All)
- DatabaseAdminClient.ListOperations
- DatabaseAdminClient.ListOperations (All)
- DatabaseAdminClient.RestoreDatabase
- DatabaseAdminClient.SetIamPolicy
- DatabaseAdminClient.TestIamPermissions
- DatabaseAdminClient.UpdateBackup
- DatabaseAdminClient.UpdateBackupSchedule
- DatabaseAdminClient.UpdateDatabase
- DatabaseAdminClient.UpdateDatabaseDdl
- NewDatabaseAdminClient
- NewDatabaseAdminRESTClient
Functions ¶
func DatabaseAdminDatabasePath ¶
DatabaseAdminDatabasePath returns the path for the database resource.
Deprecated: Use
fmt.Sprintf("projects/%s/instances/%s/databases/%s", project, instance, database)
instead.
func DatabaseAdminInstancePath ¶
DatabaseAdminInstancePath returns the path for the instance resource.
Deprecated: Use
fmt.Sprintf("projects/%s/instances/%s", project, instance)
instead.
func DefaultAuthScopes ¶
func DefaultAuthScopes() []string
DefaultAuthScopes reports the default set of authentication scopes to use with this package.
Types ¶
type BackupIterator ¶
type BackupIterator struct { // Response is the raw response for the current page. // It must be cast to the RPC response type. // Calling Next() or InternalFetch() updates this value. Response interface{} // InternalFetch is for use by the Google Cloud Libraries only. // It is not part of the stable interface of this package. // // InternalFetch returns results from a single call to the underlying RPC. // The number of results is no greater than pageSize. // If there are no more results, nextPageToken is empty and err is nil. InternalFetch func(pageSize int, pageToken string) (results []*databasepb.Backup, nextPageToken string, err error) // contains filtered or unexported fields }
BackupIterator manages a stream of *databasepb.Backup.
func (*BackupIterator) All ¶
func (it *BackupIterator) All() iter.Seq2[*databasepb.Backup, error]
All returns an iterator. If an error is returned by the iterator, the iterator will stop after that iteration.
func (*BackupIterator) Next ¶
func (it *BackupIterator) Next() (*databasepb.Backup, error)
Next returns the next result. Its second return value is iterator.Done if there are no more results. Once Next returns Done, all subsequent calls will return Done.
func (*BackupIterator) PageInfo ¶
func (it *BackupIterator) PageInfo() *iterator.PageInfo
PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
type BackupScheduleIterator ¶
type BackupScheduleIterator struct { // Response is the raw response for the current page. // It must be cast to the RPC response type. // Calling Next() or InternalFetch() updates this value. Response interface{} // InternalFetch is for use by the Google Cloud Libraries only. // It is not part of the stable interface of this package. // // InternalFetch returns results from a single call to the underlying RPC. // The number of results is no greater than pageSize. // If there are no more results, nextPageToken is empty and err is nil. InternalFetch func(pageSize int, pageToken string) (results []*databasepb.BackupSchedule, nextPageToken string, err error) // contains filtered or unexported fields }
BackupScheduleIterator manages a stream of *databasepb.BackupSchedule.
func (*BackupScheduleIterator) All ¶
func (it *BackupScheduleIterator) All() iter.Seq2[*databasepb.BackupSchedule, error]
All returns an iterator. If an error is returned by the iterator, the iterator will stop after that iteration.
func (*BackupScheduleIterator) Next ¶
func (it *BackupScheduleIterator) Next() (*databasepb.BackupSchedule, error)
Next returns the next result. Its second return value is iterator.Done if there are no more results. Once Next returns Done, all subsequent calls will return Done.
func (*BackupScheduleIterator) PageInfo ¶
func (it *BackupScheduleIterator) PageInfo() *iterator.PageInfo
PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
type CopyBackupOperation ¶
type CopyBackupOperation struct {
// contains filtered or unexported fields
}
CopyBackupOperation manages a long-running operation from CopyBackup.
func (*CopyBackupOperation) Done ¶
func (op *CopyBackupOperation) Done() bool
Done reports whether the long-running operation has completed.
func (*CopyBackupOperation) Metadata ¶
func (op *CopyBackupOperation) Metadata() (*databasepb.CopyBackupMetadata, error)
Metadata returns metadata associated with the long-running operation. Metadata itself does not contact the server, but Poll does. To get the latest metadata, call this method after a successful call to Poll. If the metadata is not available, the returned metadata and error are both nil.
func (*CopyBackupOperation) Name ¶
func (op *CopyBackupOperation) Name() string
Name returns the name of the long-running operation. The name is assigned by the server and is unique within the service from which the operation is created.
func (*CopyBackupOperation) Poll ¶
func (op *CopyBackupOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*databasepb.Backup, error)
Poll fetches the latest state of the long-running operation.
Poll also fetches the latest metadata, which can be retrieved by Metadata.
If Poll fails, the error is returned and op is unmodified. If Poll succeeds and the operation has completed with failure, the error is returned and op.Done will return true. If Poll succeeds and the operation has completed successfully, op.Done will return true, and the response of the operation is returned. If Poll succeeds and the operation has not completed, the returned response and error are both nil.
func (*CopyBackupOperation) Wait ¶
func (op *CopyBackupOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*databasepb.Backup, error)
Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
See documentation of Poll for error-handling information.
type CreateBackupOperation ¶
type CreateBackupOperation struct {
// contains filtered or unexported fields
}
CreateBackupOperation manages a long-running operation from CreateBackup.
func (*CreateBackupOperation) Done ¶
func (op *CreateBackupOperation) Done() bool
Done reports whether the long-running operation has completed.
func (*CreateBackupOperation) Metadata ¶
func (op *CreateBackupOperation) Metadata() (*databasepb.CreateBackupMetadata, error)
Metadata returns metadata associated with the long-running operation. Metadata itself does not contact the server, but Poll does. To get the latest metadata, call this method after a successful call to Poll. If the metadata is not available, the returned metadata and error are both nil.
func (*CreateBackupOperation) Name ¶
func (op *CreateBackupOperation) Name() string
Name returns the name of the long-running operation. The name is assigned by the server and is unique within the service from which the operation is created.
func (*CreateBackupOperation) Poll ¶
func (op *CreateBackupOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*databasepb.Backup, error)
Poll fetches the latest state of the long-running operation.
Poll also fetches the latest metadata, which can be retrieved by Metadata.
If Poll fails, the error is returned and op is unmodified. If Poll succeeds and the operation has completed with failure, the error is returned and op.Done will return true. If Poll succeeds and the operation has completed successfully, op.Done will return true, and the response of the operation is returned. If Poll succeeds and the operation has not completed, the returned response and error are both nil.
func (*CreateBackupOperation) Wait ¶
func (op *CreateBackupOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*databasepb.Backup, error)
Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
See documentation of Poll for error-handling information.
type CreateDatabaseOperation ¶
type CreateDatabaseOperation struct {
// contains filtered or unexported fields
}
CreateDatabaseOperation manages a long-running operation from CreateDatabase.
func (*CreateDatabaseOperation) Done ¶
func (op *CreateDatabaseOperation) Done() bool
Done reports whether the long-running operation has completed.
func (*CreateDatabaseOperation) Metadata ¶
func (op *CreateDatabaseOperation) Metadata() (*databasepb.CreateDatabaseMetadata, error)
Metadata returns metadata associated with the long-running operation. Metadata itself does not contact the server, but Poll does. To get the latest metadata, call this method after a successful call to Poll. If the metadata is not available, the returned metadata and error are both nil.
func (*CreateDatabaseOperation) Name ¶
func (op *CreateDatabaseOperation) Name() string
Name returns the name of the long-running operation. The name is assigned by the server and is unique within the service from which the operation is created.
func (*CreateDatabaseOperation) Poll ¶
func (op *CreateDatabaseOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*databasepb.Database, error)
Poll fetches the latest state of the long-running operation.
Poll also fetches the latest metadata, which can be retrieved by Metadata.
If Poll fails, the error is returned and op is unmodified. If Poll succeeds and the operation has completed with failure, the error is returned and op.Done will return true. If Poll succeeds and the operation has completed successfully, op.Done will return true, and the response of the operation is returned. If Poll succeeds and the operation has not completed, the returned response and error are both nil.
func (*CreateDatabaseOperation) Wait ¶
func (op *CreateDatabaseOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*databasepb.Database, error)
Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
See documentation of Poll for error-handling information.
type DatabaseAdminCallOptions ¶
type DatabaseAdminCallOptions struct { ListDatabases []gax.CallOption CreateDatabase []gax.CallOption GetDatabase []gax.CallOption UpdateDatabase []gax.CallOption UpdateDatabaseDdl []gax.CallOption DropDatabase []gax.CallOption GetDatabaseDdl []gax.CallOption SetIamPolicy []gax.CallOption GetIamPolicy []gax.CallOption TestIamPermissions []gax.CallOption CreateBackup []gax.CallOption CopyBackup []gax.CallOption GetBackup []gax.CallOption UpdateBackup []gax.CallOption DeleteBackup []gax.CallOption ListBackups []gax.CallOption RestoreDatabase []gax.CallOption ListDatabaseOperations []gax.CallOption ListBackupOperations []gax.CallOption ListDatabaseRoles []gax.CallOption AddSplitPoints []gax.CallOption CreateBackupSchedule []gax.CallOption GetBackupSchedule []gax.CallOption UpdateBackupSchedule []gax.CallOption DeleteBackupSchedule []gax.CallOption ListBackupSchedules []gax.CallOption CancelOperation []gax.CallOption DeleteOperation []gax.CallOption GetOperation []gax.CallOption ListOperations []gax.CallOption }
DatabaseAdminCallOptions contains the retry settings for each method of DatabaseAdminClient.
type DatabaseAdminClient ¶
type DatabaseAdminClient struct { // The call options for this service. CallOptions *DatabaseAdminCallOptions // LROClient is used internally to handle long-running operations. // It is exposed so that its CallOptions can be modified if required. // Users should not Close this client. LROClient *lroauto.OperationsClient // contains filtered or unexported fields }
DatabaseAdminClient is a client for interacting with Cloud Spanner API. Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
Cloud Spanner Database Admin API
The Cloud Spanner Database Admin API can be used to:
create, drop, and list databases update the schema of pre-existing databases create, delete, copy and list backups for a database restore a database from an existing backup
func NewDatabaseAdminClient ¶
func NewDatabaseAdminClient(ctx context.Context, opts ...option.ClientOption) (*DatabaseAdminClient, error)
NewDatabaseAdminClient creates a new database admin client based on gRPC. The returned client must be Closed when it is done being used to clean up its underlying connections.
Cloud Spanner Database Admin API
The Cloud Spanner Database Admin API can be used to:
create, drop, and list databases update the schema of pre-existing databases create, delete, copy and list backups for a database restore a database from an existing backup
Example¶
Code:play
package main import ( "context" database "cloud.google.com/go/spanner/admin/database/apiv1" ) func main() { ctx := context.Background() // This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in: // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options c, err := database.NewDatabaseAdminClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() // TODO: Use client. _ = c }
func NewDatabaseAdminRESTClient ¶
func NewDatabaseAdminRESTClient(ctx context.Context, opts ...option.ClientOption) (*DatabaseAdminClient, error)
NewDatabaseAdminRESTClient creates a new database admin rest client.
Cloud Spanner Database Admin API
The Cloud Spanner Database Admin API can be used to:
create, drop, and list databases update the schema of pre-existing databases create, delete, copy and list backups for a database restore a database from an existing backup
Example¶
Code:play
package main import ( "context" database "cloud.google.com/go/spanner/admin/database/apiv1" ) func main() { ctx := context.Background() // This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in: // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options c, err := database.NewDatabaseAdminRESTClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() // TODO: Use client. _ = c }
func (*DatabaseAdminClient) AddSplitPoints ¶
func (c *DatabaseAdminClient) AddSplitPoints(ctx context.Context, req *databasepb.AddSplitPointsRequest, opts ...gax.CallOption) (*databasepb.AddSplitPointsResponse, error)
AddSplitPoints adds split points to specified tables, indexes of a database.
Code:play
Example¶
package main
import (
"context"
database "cloud.google.com/go/spanner/admin/database/apiv1"
databasepb "cloud.google.com/go/spanner/admin/database/apiv1/databasepb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &databasepb.AddSplitPointsRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/spanner/admin/database/apiv1/databasepb#AddSplitPointsRequest.
}
resp, err := c.AddSplitPoints(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*DatabaseAdminClient) CancelOperation ¶
func (c *DatabaseAdminClient) CancelOperation(ctx context.Context, req *longrunningpb.CancelOperationRequest, opts ...gax.CallOption) error
CancelOperation is a utility method from google.longrunning.Operations.
Code:play
Example¶
package main
import (
"context"
longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
database "cloud.google.com/go/spanner/admin/database/apiv1"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &longrunningpb.CancelOperationRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#CancelOperationRequest.
}
err = c.CancelOperation(ctx, req)
if err != nil {
// TODO: Handle error.
}
}
func (*DatabaseAdminClient) Close ¶
func (c *DatabaseAdminClient) Close() error
Close closes the connection to the API service. The user should invoke this when the client is no longer required.
func (*DatabaseAdminClient) Connection ¶
func (c *DatabaseAdminClient) Connection() *grpc.ClientConn
Connection returns a connection to the API service.
Deprecated: Connections are now pooled so this method does not always return the same resource.
func (*DatabaseAdminClient) CopyBackup ¶
func (c *DatabaseAdminClient) CopyBackup(ctx context.Context, req *databasepb.CopyBackupRequest, opts ...gax.CallOption) (*CopyBackupOperation, error)
CopyBackup starts copying a Cloud Spanner Backup.
The returned backup [long-running operation][google.longrunning.Operation]
will have a name of the format
projects/<project>/instances/<instance>/backups/<backup>/operations/<operation_id>
and can be used to track copying of the backup. The operation is associated
with the destination backup.
The metadata field type is
CopyBackupMetadata.
The response field type is
Backup, if successful.
Cancelling the returned operation will stop the copying and delete the
destination backup. Concurrent CopyBackup requests can run on the same
source backup.
Code:play
Example¶
package main
import (
"context"
database "cloud.google.com/go/spanner/admin/database/apiv1"
databasepb "cloud.google.com/go/spanner/admin/database/apiv1/databasepb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &databasepb.CopyBackupRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/spanner/admin/database/apiv1/databasepb#CopyBackupRequest.
}
op, err := c.CopyBackup(ctx, req)
if err != nil {
// TODO: Handle error.
}
resp, err := op.Wait(ctx)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*DatabaseAdminClient) CopyBackupOperation ¶
func (c *DatabaseAdminClient) CopyBackupOperation(name string) *CopyBackupOperation
CopyBackupOperation returns a new CopyBackupOperation from a given name. The name must be that of a previously created CopyBackupOperation, possibly from a different process.
func (*DatabaseAdminClient) CreateBackup ¶
func (c *DatabaseAdminClient) CreateBackup(ctx context.Context, req *databasepb.CreateBackupRequest, opts ...gax.CallOption) (*CreateBackupOperation, error)
CreateBackup starts creating a new Cloud Spanner Backup.
The returned backup [long-running operation][google.longrunning.Operation]
will have a name of the format
projects/<project>/instances/<instance>/backups/<backup>/operations/<operation_id>
and can be used to track creation of the backup. The
metadata field type is
CreateBackupMetadata.
The response field type is
Backup, if successful.
Cancelling the returned operation will stop the creation and delete the
backup. There can be only one pending backup creation per database. Backup
creation of different databases can run concurrently.
Code:play
Example¶
package main
import (
"context"
database "cloud.google.com/go/spanner/admin/database/apiv1"
databasepb "cloud.google.com/go/spanner/admin/database/apiv1/databasepb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &databasepb.CreateBackupRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/spanner/admin/database/apiv1/databasepb#CreateBackupRequest.
}
op, err := c.CreateBackup(ctx, req)
if err != nil {
// TODO: Handle error.
}
resp, err := op.Wait(ctx)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*DatabaseAdminClient) CreateBackupOperation ¶
func (c *DatabaseAdminClient) CreateBackupOperation(name string) *CreateBackupOperation
CreateBackupOperation returns a new CreateBackupOperation from a given name. The name must be that of a previously created CreateBackupOperation, possibly from a different process.
func (*DatabaseAdminClient) CreateBackupSchedule ¶
func (c *DatabaseAdminClient) CreateBackupSchedule(ctx context.Context, req *databasepb.CreateBackupScheduleRequest, opts ...gax.CallOption) (*databasepb.BackupSchedule, error)
CreateBackupSchedule creates a new backup schedule.
Code:play
Example¶
package main
import (
"context"
database "cloud.google.com/go/spanner/admin/database/apiv1"
databasepb "cloud.google.com/go/spanner/admin/database/apiv1/databasepb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &databasepb.CreateBackupScheduleRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/spanner/admin/database/apiv1/databasepb#CreateBackupScheduleRequest.
}
resp, err := c.CreateBackupSchedule(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*DatabaseAdminClient) CreateDatabase ¶
func (c *DatabaseAdminClient) CreateDatabase(ctx context.Context, req *databasepb.CreateDatabaseRequest, opts ...gax.CallOption) (*CreateDatabaseOperation, error)
CreateDatabase creates a new Cloud Spanner database and starts to prepare it for serving.
The returned [long-running operation][google.longrunning.Operation] will
have a name of the format <database_name>/operations/<operation_id> and
can be used to track preparation of the database. The
metadata field type is
CreateDatabaseMetadata.
The response field type is
Database, if successful.
Code:play
Example¶
package main
import (
"context"
database "cloud.google.com/go/spanner/admin/database/apiv1"
databasepb "cloud.google.com/go/spanner/admin/database/apiv1/databasepb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &databasepb.CreateDatabaseRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/spanner/admin/database/apiv1/databasepb#CreateDatabaseRequest.
}
op, err := c.CreateDatabase(ctx, req)
if err != nil {
// TODO: Handle error.
}
resp, err := op.Wait(ctx)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*DatabaseAdminClient) CreateDatabaseOperation ¶
func (c *DatabaseAdminClient) CreateDatabaseOperation(name string) *CreateDatabaseOperation
CreateDatabaseOperation returns a new CreateDatabaseOperation from a given name. The name must be that of a previously created CreateDatabaseOperation, possibly from a different process.
func (*DatabaseAdminClient) CreateDatabaseWithRetry ¶
func (c *DatabaseAdminClient) CreateDatabaseWithRetry(ctx context.Context, req *databasepb.CreateDatabaseRequest, opts ...gax.CallOption) (*CreateDatabaseOperation, error)
CreateDatabaseWithRetry creates a new database and retries the call if the backend returns a retryable error. The actual CreateDatabase RPC is only retried if the initial call did not reach the server. In other cases, the client will query the backend for the long-running operation that was created by the initial RPC and return that operation.
func (*DatabaseAdminClient) DeleteBackup ¶
func (c *DatabaseAdminClient) DeleteBackup(ctx context.Context, req *databasepb.DeleteBackupRequest, opts ...gax.CallOption) error
DeleteBackup deletes a pending or completed
Backup.
Code:play
Example¶
package main
import (
"context"
database "cloud.google.com/go/spanner/admin/database/apiv1"
databasepb "cloud.google.com/go/spanner/admin/database/apiv1/databasepb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &databasepb.DeleteBackupRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/spanner/admin/database/apiv1/databasepb#DeleteBackupRequest.
}
err = c.DeleteBackup(ctx, req)
if err != nil {
// TODO: Handle error.
}
}
func (*DatabaseAdminClient) DeleteBackupSchedule ¶
func (c *DatabaseAdminClient) DeleteBackupSchedule(ctx context.Context, req *databasepb.DeleteBackupScheduleRequest, opts ...gax.CallOption) error
DeleteBackupSchedule deletes a backup schedule.
Code:play
Example¶
package main
import (
"context"
database "cloud.google.com/go/spanner/admin/database/apiv1"
databasepb "cloud.google.com/go/spanner/admin/database/apiv1/databasepb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &databasepb.DeleteBackupScheduleRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/spanner/admin/database/apiv1/databasepb#DeleteBackupScheduleRequest.
}
err = c.DeleteBackupSchedule(ctx, req)
if err != nil {
// TODO: Handle error.
}
}
func (*DatabaseAdminClient) DeleteOperation ¶
func (c *DatabaseAdminClient) DeleteOperation(ctx context.Context, req *longrunningpb.DeleteOperationRequest, opts ...gax.CallOption) error
DeleteOperation is a utility method from google.longrunning.Operations.
Code:play
Example¶
package main
import (
"context"
longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
database "cloud.google.com/go/spanner/admin/database/apiv1"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &longrunningpb.DeleteOperationRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#DeleteOperationRequest.
}
err = c.DeleteOperation(ctx, req)
if err != nil {
// TODO: Handle error.
}
}
func (*DatabaseAdminClient) DropDatabase ¶
func (c *DatabaseAdminClient) DropDatabase(ctx context.Context, req *databasepb.DropDatabaseRequest, opts ...gax.CallOption) error
DropDatabase drops (aka deletes) a Cloud Spanner database.
Completed backups for the database will be retained according to their
expire_time.
Note: Cloud Spanner might continue to accept requests for a few seconds
after the database has been deleted.
Code:play
Example¶
package main
import (
"context"
database "cloud.google.com/go/spanner/admin/database/apiv1"
databasepb "cloud.google.com/go/spanner/admin/database/apiv1/databasepb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &databasepb.DropDatabaseRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/spanner/admin/database/apiv1/databasepb#DropDatabaseRequest.
}
err = c.DropDatabase(ctx, req)
if err != nil {
// TODO: Handle error.
}
}
func (*DatabaseAdminClient) GetBackup ¶
func (c *DatabaseAdminClient) GetBackup(ctx context.Context, req *databasepb.GetBackupRequest, opts ...gax.CallOption) (*databasepb.Backup, error)
GetBackup gets metadata on a pending or completed
Backup.
Code:play
Example¶
package main
import (
"context"
database "cloud.google.com/go/spanner/admin/database/apiv1"
databasepb "cloud.google.com/go/spanner/admin/database/apiv1/databasepb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &databasepb.GetBackupRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/spanner/admin/database/apiv1/databasepb#GetBackupRequest.
}
resp, err := c.GetBackup(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*DatabaseAdminClient) GetBackupSchedule ¶
func (c *DatabaseAdminClient) GetBackupSchedule(ctx context.Context, req *databasepb.GetBackupScheduleRequest, opts ...gax.CallOption) (*databasepb.BackupSchedule, error)
GetBackupSchedule gets backup schedule for the input schedule name.
Code:play
Example¶
package main
import (
"context"
database "cloud.google.com/go/spanner/admin/database/apiv1"
databasepb "cloud.google.com/go/spanner/admin/database/apiv1/databasepb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &databasepb.GetBackupScheduleRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/spanner/admin/database/apiv1/databasepb#GetBackupScheduleRequest.
}
resp, err := c.GetBackupSchedule(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*DatabaseAdminClient) GetDatabase ¶
func (c *DatabaseAdminClient) GetDatabase(ctx context.Context, req *databasepb.GetDatabaseRequest, opts ...gax.CallOption) (*databasepb.Database, error)
GetDatabase gets the state of a Cloud Spanner database.
Code:play
Example¶
package main
import (
"context"
database "cloud.google.com/go/spanner/admin/database/apiv1"
databasepb "cloud.google.com/go/spanner/admin/database/apiv1/databasepb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &databasepb.GetDatabaseRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/spanner/admin/database/apiv1/databasepb#GetDatabaseRequest.
}
resp, err := c.GetDatabase(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*DatabaseAdminClient) GetDatabaseDdl ¶
func (c *DatabaseAdminClient) GetDatabaseDdl(ctx context.Context, req *databasepb.GetDatabaseDdlRequest, opts ...gax.CallOption) (*databasepb.GetDatabaseDdlResponse, error)
GetDatabaseDdl returns the schema of a Cloud Spanner database as a list of formatted
DDL statements. This method does not show pending schema updates, those may
be queried using the Operations API.
Code:play
Example¶
package main
import (
"context"
database "cloud.google.com/go/spanner/admin/database/apiv1"
databasepb "cloud.google.com/go/spanner/admin/database/apiv1/databasepb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &databasepb.GetDatabaseDdlRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/spanner/admin/database/apiv1/databasepb#GetDatabaseDdlRequest.
}
resp, err := c.GetDatabaseDdl(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*DatabaseAdminClient) GetIamPolicy ¶
func (c *DatabaseAdminClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error)
GetIamPolicy gets the access control policy for a database or backup resource. Returns an empty policy if a database or backup exists but does not have a policy set.
Authorization requires spanner.databases.getIamPolicy permission on
resource.
For backups, authorization requires spanner.backups.getIamPolicy
permission on resource.
Code:play
Example¶
package main
import (
"context"
iampb "cloud.google.com/go/iam/apiv1/iampb"
database "cloud.google.com/go/spanner/admin/database/apiv1"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &iampb.GetIamPolicyRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#GetIamPolicyRequest.
}
resp, err := c.GetIamPolicy(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*DatabaseAdminClient) GetOperation ¶
func (c *DatabaseAdminClient) GetOperation(ctx context.Context, req *longrunningpb.GetOperationRequest, opts ...gax.CallOption) (*longrunningpb.Operation, error)
GetOperation is a utility method from google.longrunning.Operations.
Code:play
Example¶
package main
import (
"context"
longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
database "cloud.google.com/go/spanner/admin/database/apiv1"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &longrunningpb.GetOperationRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#GetOperationRequest.
}
resp, err := c.GetOperation(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*DatabaseAdminClient) ListBackupOperations ¶
func (c *DatabaseAdminClient) ListBackupOperations(ctx context.Context, req *databasepb.ListBackupOperationsRequest, opts ...gax.CallOption) *OperationIterator
ListBackupOperations lists the backup [long-running operations][google.longrunning.Operation] in
the given instance. A backup operation has a name of the form
projects/<project>/instances/<instance>/backups/<backup>/operations/<operation>.
The long-running operation
metadata field type
metadata.type_url describes the type of the metadata. Operations returned
include those that have completed/failed/canceled within the last 7 days,
and pending operations. Operations returned are ordered by
operation.metadata.value.progress.start_time in descending order starting
from the most recently started operation.
Code:play
Code:play
Example¶
package main
import (
"context"
database "cloud.google.com/go/spanner/admin/database/apiv1"
databasepb "cloud.google.com/go/spanner/admin/database/apiv1/databasepb"
"google.golang.org/api/iterator"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &databasepb.ListBackupOperationsRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/spanner/admin/database/apiv1/databasepb#ListBackupOperationsRequest.
}
it := c.ListBackupOperations(ctx, req)
for {
resp, err := it.Next()
if err == iterator.Done {
break
}
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
// If you need to access the underlying RPC response,
// you can do so by casting the `Response` as below.
// Otherwise, remove this line. Only populated after
// first call to Next(). Not safe for concurrent access.
_ = it.Response.(*databasepb.ListBackupOperationsResponse)
}
}
Example (All)¶
package main
import (
"context"
database "cloud.google.com/go/spanner/admin/database/apiv1"
databasepb "cloud.google.com/go/spanner/admin/database/apiv1/databasepb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &databasepb.ListBackupOperationsRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/spanner/admin/database/apiv1/databasepb#ListBackupOperationsRequest.
}
for resp, err := range c.ListBackupOperations(ctx, req).All() {
if err != nil {
// TODO: Handle error and break/return/continue. Iteration will stop after any error.
}
// TODO: Use resp.
_ = resp
}
}
func (*DatabaseAdminClient) ListBackupSchedules ¶
func (c *DatabaseAdminClient) ListBackupSchedules(ctx context.Context, req *databasepb.ListBackupSchedulesRequest, opts ...gax.CallOption) *BackupScheduleIterator
ListBackupSchedules lists all the backup schedules for the database.
Code:play
Code:play
Example¶
package main
import (
"context"
database "cloud.google.com/go/spanner/admin/database/apiv1"
databasepb "cloud.google.com/go/spanner/admin/database/apiv1/databasepb"
"google.golang.org/api/iterator"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &databasepb.ListBackupSchedulesRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/spanner/admin/database/apiv1/databasepb#ListBackupSchedulesRequest.
}
it := c.ListBackupSchedules(ctx, req)
for {
resp, err := it.Next()
if err == iterator.Done {
break
}
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
// If you need to access the underlying RPC response,
// you can do so by casting the `Response` as below.
// Otherwise, remove this line. Only populated after
// first call to Next(). Not safe for concurrent access.
_ = it.Response.(*databasepb.ListBackupSchedulesResponse)
}
}
Example (All)¶
package main
import (
"context"
database "cloud.google.com/go/spanner/admin/database/apiv1"
databasepb "cloud.google.com/go/spanner/admin/database/apiv1/databasepb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &databasepb.ListBackupSchedulesRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/spanner/admin/database/apiv1/databasepb#ListBackupSchedulesRequest.
}
for resp, err := range c.ListBackupSchedules(ctx, req).All() {
if err != nil {
// TODO: Handle error and break/return/continue. Iteration will stop after any error.
}
// TODO: Use resp.
_ = resp
}
}
func (*DatabaseAdminClient) ListBackups ¶
func (c *DatabaseAdminClient) ListBackups(ctx context.Context, req *databasepb.ListBackupsRequest, opts ...gax.CallOption) *BackupIterator
ListBackups lists completed and pending backups.
Backups returned are ordered by create_time in descending order,
starting from the most recent create_time.
Code:play
Code:play
Example¶
package main
import (
"context"
database "cloud.google.com/go/spanner/admin/database/apiv1"
databasepb "cloud.google.com/go/spanner/admin/database/apiv1/databasepb"
"google.golang.org/api/iterator"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &databasepb.ListBackupsRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/spanner/admin/database/apiv1/databasepb#ListBackupsRequest.
}
it := c.ListBackups(ctx, req)
for {
resp, err := it.Next()
if err == iterator.Done {
break
}
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
// If you need to access the underlying RPC response,
// you can do so by casting the `Response` as below.
// Otherwise, remove this line. Only populated after
// first call to Next(). Not safe for concurrent access.
_ = it.Response.(*databasepb.ListBackupsResponse)
}
}
Example (All)¶
package main
import (
"context"
database "cloud.google.com/go/spanner/admin/database/apiv1"
databasepb "cloud.google.com/go/spanner/admin/database/apiv1/databasepb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &databasepb.ListBackupsRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/spanner/admin/database/apiv1/databasepb#ListBackupsRequest.
}
for resp, err := range c.ListBackups(ctx, req).All() {
if err != nil {
// TODO: Handle error and break/return/continue. Iteration will stop after any error.
}
// TODO: Use resp.
_ = resp
}
}
func (*DatabaseAdminClient) ListDatabaseOperations ¶
func (c *DatabaseAdminClient) ListDatabaseOperations(ctx context.Context, req *databasepb.ListDatabaseOperationsRequest, opts ...gax.CallOption) *OperationIterator
ListDatabaseOperations lists database [longrunning-operations][google.longrunning.Operation].
A database operation has a name of the form
projects/<project>/instances/<instance>/databases/<database>/operations/<operation>.
The long-running operation
metadata field type
metadata.type_url describes the type of the metadata. Operations returned
include those that have completed/failed/canceled within the last 7 days,
and pending operations.
Code:play
Code:play
Example¶
package main
import (
"context"
database "cloud.google.com/go/spanner/admin/database/apiv1"
databasepb "cloud.google.com/go/spanner/admin/database/apiv1/databasepb"
"google.golang.org/api/iterator"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &databasepb.ListDatabaseOperationsRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/spanner/admin/database/apiv1/databasepb#ListDatabaseOperationsRequest.
}
it := c.ListDatabaseOperations(ctx, req)
for {
resp, err := it.Next()
if err == iterator.Done {
break
}
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
// If you need to access the underlying RPC response,
// you can do so by casting the `Response` as below.
// Otherwise, remove this line. Only populated after
// first call to Next(). Not safe for concurrent access.
_ = it.Response.(*databasepb.ListDatabaseOperationsResponse)
}
}
Example (All)¶
package main
import (
"context"
database "cloud.google.com/go/spanner/admin/database/apiv1"
databasepb "cloud.google.com/go/spanner/admin/database/apiv1/databasepb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &databasepb.ListDatabaseOperationsRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/spanner/admin/database/apiv1/databasepb#ListDatabaseOperationsRequest.
}
for resp, err := range c.ListDatabaseOperations(ctx, req).All() {
if err != nil {
// TODO: Handle error and break/return/continue. Iteration will stop after any error.
}
// TODO: Use resp.
_ = resp
}
}
func (*DatabaseAdminClient) ListDatabaseRoles ¶
func (c *DatabaseAdminClient) ListDatabaseRoles(ctx context.Context, req *databasepb.ListDatabaseRolesRequest, opts ...gax.CallOption) *DatabaseRoleIterator
ListDatabaseRoles lists Cloud Spanner database roles.
Code:play
Code:play
Example¶
package main
import (
"context"
database "cloud.google.com/go/spanner/admin/database/apiv1"
databasepb "cloud.google.com/go/spanner/admin/database/apiv1/databasepb"
"google.golang.org/api/iterator"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &databasepb.ListDatabaseRolesRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/spanner/admin/database/apiv1/databasepb#ListDatabaseRolesRequest.
}
it := c.ListDatabaseRoles(ctx, req)
for {
resp, err := it.Next()
if err == iterator.Done {
break
}
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
// If you need to access the underlying RPC response,
// you can do so by casting the `Response` as below.
// Otherwise, remove this line. Only populated after
// first call to Next(). Not safe for concurrent access.
_ = it.Response.(*databasepb.ListDatabaseRolesResponse)
}
}
Example (All)¶
package main
import (
"context"
database "cloud.google.com/go/spanner/admin/database/apiv1"
databasepb "cloud.google.com/go/spanner/admin/database/apiv1/databasepb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &databasepb.ListDatabaseRolesRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/spanner/admin/database/apiv1/databasepb#ListDatabaseRolesRequest.
}
for resp, err := range c.ListDatabaseRoles(ctx, req).All() {
if err != nil {
// TODO: Handle error and break/return/continue. Iteration will stop after any error.
}
// TODO: Use resp.
_ = resp
}
}
func (*DatabaseAdminClient) ListDatabases ¶
func (c *DatabaseAdminClient) ListDatabases(ctx context.Context, req *databasepb.ListDatabasesRequest, opts ...gax.CallOption) *DatabaseIterator
ListDatabases lists Cloud Spanner databases.
Code:play
Code:play
Example¶
package main
import (
"context"
database "cloud.google.com/go/spanner/admin/database/apiv1"
databasepb "cloud.google.com/go/spanner/admin/database/apiv1/databasepb"
"google.golang.org/api/iterator"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &databasepb.ListDatabasesRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/spanner/admin/database/apiv1/databasepb#ListDatabasesRequest.
}
it := c.ListDatabases(ctx, req)
for {
resp, err := it.Next()
if err == iterator.Done {
break
}
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
// If you need to access the underlying RPC response,
// you can do so by casting the `Response` as below.
// Otherwise, remove this line. Only populated after
// first call to Next(). Not safe for concurrent access.
_ = it.Response.(*databasepb.ListDatabasesResponse)
}
}
Example (All)¶
package main
import (
"context"
database "cloud.google.com/go/spanner/admin/database/apiv1"
databasepb "cloud.google.com/go/spanner/admin/database/apiv1/databasepb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &databasepb.ListDatabasesRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/spanner/admin/database/apiv1/databasepb#ListDatabasesRequest.
}
for resp, err := range c.ListDatabases(ctx, req).All() {
if err != nil {
// TODO: Handle error and break/return/continue. Iteration will stop after any error.
}
// TODO: Use resp.
_ = resp
}
}
func (*DatabaseAdminClient) ListOperations ¶
func (c *DatabaseAdminClient) ListOperations(ctx context.Context, req *longrunningpb.ListOperationsRequest, opts ...gax.CallOption) *OperationIterator
ListOperations is a utility method from google.longrunning.Operations.
Code:play
Code:play
Example¶
package main
import (
"context"
longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
database "cloud.google.com/go/spanner/admin/database/apiv1"
"google.golang.org/api/iterator"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &longrunningpb.ListOperationsRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#ListOperationsRequest.
}
it := c.ListOperations(ctx, req)
for {
resp, err := it.Next()
if err == iterator.Done {
break
}
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
// If you need to access the underlying RPC response,
// you can do so by casting the `Response` as below.
// Otherwise, remove this line. Only populated after
// first call to Next(). Not safe for concurrent access.
_ = it.Response.(*longrunningpb.ListOperationsResponse)
}
}
Example (All)¶
package main
import (
"context"
longrunningpb "cloud.google.com/go/longrunning/autogen/longrunningpb"
database "cloud.google.com/go/spanner/admin/database/apiv1"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &longrunningpb.ListOperationsRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#ListOperationsRequest.
}
for resp, err := range c.ListOperations(ctx, req).All() {
if err != nil {
// TODO: Handle error and break/return/continue. Iteration will stop after any error.
}
// TODO: Use resp.
_ = resp
}
}
func (*DatabaseAdminClient) RestoreDatabase ¶
func (c *DatabaseAdminClient) RestoreDatabase(ctx context.Context, req *databasepb.RestoreDatabaseRequest, opts ...gax.CallOption) (*RestoreDatabaseOperation, error)
RestoreDatabase create a new database by restoring from a completed backup. The new
database must be in the same project and in an instance with the same
instance configuration as the instance containing
the backup. The returned database [long-running
operation][google.longrunning.Operation] has a name of the format
projects/<project>/instances/<instance>/databases/<database>/operations/<operation_id>,
and can be used to track the progress of the operation, and to cancel it.
The metadata field type is
RestoreDatabaseMetadata.
The response type
is Database, if
successful. Cancelling the returned operation will stop the restore and
delete the database.
There can be only one database being restored into an instance at a time.
Once the restore operation completes, a new restore operation can be
initiated, without waiting for the optimize operation associated with the
first restore to complete.
Code:play
Example¶
package main
import (
"context"
database "cloud.google.com/go/spanner/admin/database/apiv1"
databasepb "cloud.google.com/go/spanner/admin/database/apiv1/databasepb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &databasepb.RestoreDatabaseRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/spanner/admin/database/apiv1/databasepb#RestoreDatabaseRequest.
}
op, err := c.RestoreDatabase(ctx, req)
if err != nil {
// TODO: Handle error.
}
resp, err := op.Wait(ctx)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*DatabaseAdminClient) RestoreDatabaseOperation ¶
func (c *DatabaseAdminClient) RestoreDatabaseOperation(name string) *RestoreDatabaseOperation
RestoreDatabaseOperation returns a new RestoreDatabaseOperation from a given name. The name must be that of a previously created RestoreDatabaseOperation, possibly from a different process.
func (*DatabaseAdminClient) SetIamPolicy ¶
func (c *DatabaseAdminClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest, opts ...gax.CallOption) (*iampb.Policy, error)
SetIamPolicy sets the access control policy on a database or backup resource. Replaces any existing policy.
Authorization requires spanner.databases.setIamPolicy
permission on resource.
For backups, authorization requires spanner.backups.setIamPolicy
permission on resource.
Code:play
Example¶
package main
import (
"context"
iampb "cloud.google.com/go/iam/apiv1/iampb"
database "cloud.google.com/go/spanner/admin/database/apiv1"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &iampb.SetIamPolicyRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#SetIamPolicyRequest.
}
resp, err := c.SetIamPolicy(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*DatabaseAdminClient) StartBackupOperation ¶
func (c *DatabaseAdminClient) StartBackupOperation(ctx context.Context, backupID string, databasePath string, expireTime time.Time, opts ...gax.CallOption) (*CreateBackupOperation, error)
StartBackupOperation creates a backup of the given database. It will be stored as projects/<project>/instances/<instance>/backups/<backupID>. The backup will be automatically deleted by Cloud Spanner after its expiration.
backupID must be unique across an instance.
expireTime is the time the backup will expire. It is respected to microsecond granularity.
databasePath must have the form projects/<project>/instances/<instance>/databases/<database>.
func (*DatabaseAdminClient) TestIamPermissions ¶
func (c *DatabaseAdminClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest, opts ...gax.CallOption) (*iampb.TestIamPermissionsResponse, error)
TestIamPermissions returns permissions that the caller has on the specified database or backup resource.
Attempting this RPC on a non-existent Cloud Spanner database will
result in a NOT_FOUND error if the user has
spanner.databases.list permission on the containing Cloud
Spanner instance. Otherwise returns an empty set of permissions.
Calling this method on a backup that does not exist will
result in a NOT_FOUND error if the user has
spanner.backups.list permission on the containing instance.
Code:play
Example¶
package main
import (
"context"
iampb "cloud.google.com/go/iam/apiv1/iampb"
database "cloud.google.com/go/spanner/admin/database/apiv1"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &iampb.TestIamPermissionsRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/iam/apiv1/iampb#TestIamPermissionsRequest.
}
resp, err := c.TestIamPermissions(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*DatabaseAdminClient) UpdateBackup ¶
func (c *DatabaseAdminClient) UpdateBackup(ctx context.Context, req *databasepb.UpdateBackupRequest, opts ...gax.CallOption) (*databasepb.Backup, error)
UpdateBackup updates a pending or completed
Backup.
Code:play
Example¶
package main
import (
"context"
database "cloud.google.com/go/spanner/admin/database/apiv1"
databasepb "cloud.google.com/go/spanner/admin/database/apiv1/databasepb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &databasepb.UpdateBackupRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/spanner/admin/database/apiv1/databasepb#UpdateBackupRequest.
}
resp, err := c.UpdateBackup(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*DatabaseAdminClient) UpdateBackupSchedule ¶
func (c *DatabaseAdminClient) UpdateBackupSchedule(ctx context.Context, req *databasepb.UpdateBackupScheduleRequest, opts ...gax.CallOption) (*databasepb.BackupSchedule, error)
UpdateBackupSchedule updates a backup schedule.
Code:play
Example¶
package main
import (
"context"
database "cloud.google.com/go/spanner/admin/database/apiv1"
databasepb "cloud.google.com/go/spanner/admin/database/apiv1/databasepb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &databasepb.UpdateBackupScheduleRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/spanner/admin/database/apiv1/databasepb#UpdateBackupScheduleRequest.
}
resp, err := c.UpdateBackupSchedule(ctx, req)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*DatabaseAdminClient) UpdateDatabase ¶
func (c *DatabaseAdminClient) UpdateDatabase(ctx context.Context, req *databasepb.UpdateDatabaseRequest, opts ...gax.CallOption) (*UpdateDatabaseOperation, error)
UpdateDatabase updates a Cloud Spanner database. The returned [long-running operation][google.longrunning.Operation] can be used to track the progress of updating the database. If the named database does not exist, returns NOT_FOUND.
While the operation is pending:
The database’s reconciling field is set to true. Cancelling the operation is best-effort. If the cancellation succeeds, the operation metadata’s cancel_time is set, the updates are reverted, and the operation terminates with a CANCELLED status. New UpdateDatabase requests will return a FAILED_PRECONDITION error until the pending operation is done (returns successfully or with error). Reading the database via the API continues to give the pre-request values.
Upon completion of the returned operation:
The new values are in effect and readable via the API. The database’s reconciling field becomes false.
The returned [long-running operation][google.longrunning.Operation] will
have a name of the format
projects/<project>/instances/<instance>/databases/<database>/operations/<operation_id>
and can be used to track the database modification. The
metadata field type is
UpdateDatabaseMetadata.
The response field type is
Database, if successful.
Code:play
Example¶
package main
import (
"context"
database "cloud.google.com/go/spanner/admin/database/apiv1"
databasepb "cloud.google.com/go/spanner/admin/database/apiv1/databasepb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &databasepb.UpdateDatabaseRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/spanner/admin/database/apiv1/databasepb#UpdateDatabaseRequest.
}
op, err := c.UpdateDatabase(ctx, req)
if err != nil {
// TODO: Handle error.
}
resp, err := op.Wait(ctx)
if err != nil {
// TODO: Handle error.
}
// TODO: Use resp.
_ = resp
}
func (*DatabaseAdminClient) UpdateDatabaseDdl ¶
func (c *DatabaseAdminClient) UpdateDatabaseDdl(ctx context.Context, req *databasepb.UpdateDatabaseDdlRequest, opts ...gax.CallOption) (*UpdateDatabaseDdlOperation, error)
UpdateDatabaseDdl updates the schema of a Cloud Spanner database by
creating/altering/dropping tables, columns, indexes, etc. The returned
[long-running operation][google.longrunning.Operation] will have a name of
the format <database_name>/operations/<operation_id> and can be used to
track execution of the schema change(s). The
metadata field type is
UpdateDatabaseDdlMetadata.
The operation has no response.
Code:play
Example¶
package main
import (
"context"
database "cloud.google.com/go/spanner/admin/database/apiv1"
databasepb "cloud.google.com/go/spanner/admin/database/apiv1/databasepb"
)
func main() {
ctx := context.Background()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c, err := database.NewDatabaseAdminClient(ctx)
if err != nil {
// TODO: Handle error.
}
defer c.Close()
req := &databasepb.UpdateDatabaseDdlRequest{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/spanner/admin/database/apiv1/databasepb#UpdateDatabaseDdlRequest.
}
op, err := c.UpdateDatabaseDdl(ctx, req)
if err != nil {
// TODO: Handle error.
}
err = op.Wait(ctx)
if err != nil {
// TODO: Handle error.
}
}
func (*DatabaseAdminClient) UpdateDatabaseDdlOperation ¶
func (c *DatabaseAdminClient) UpdateDatabaseDdlOperation(name string) *UpdateDatabaseDdlOperation
UpdateDatabaseDdlOperation returns a new UpdateDatabaseDdlOperation from a given name. The name must be that of a previously created UpdateDatabaseDdlOperation, possibly from a different process.
func (*DatabaseAdminClient) UpdateDatabaseOperation ¶
func (c *DatabaseAdminClient) UpdateDatabaseOperation(name string) *UpdateDatabaseOperation
UpdateDatabaseOperation returns a new UpdateDatabaseOperation from a given name. The name must be that of a previously created UpdateDatabaseOperation, possibly from a different process.
type DatabaseIterator ¶
type DatabaseIterator struct { // Response is the raw response for the current page. // It must be cast to the RPC response type. // Calling Next() or InternalFetch() updates this value. Response interface{} // InternalFetch is for use by the Google Cloud Libraries only. // It is not part of the stable interface of this package. // // InternalFetch returns results from a single call to the underlying RPC. // The number of results is no greater than pageSize. // If there are no more results, nextPageToken is empty and err is nil. InternalFetch func(pageSize int, pageToken string) (results []*databasepb.Database, nextPageToken string, err error) // contains filtered or unexported fields }
DatabaseIterator manages a stream of *databasepb.Database.
func (*DatabaseIterator) All ¶
func (it *DatabaseIterator) All() iter.Seq2[*databasepb.Database, error]
All returns an iterator. If an error is returned by the iterator, the iterator will stop after that iteration.
func (*DatabaseIterator) Next ¶
func (it *DatabaseIterator) Next() (*databasepb.Database, error)
Next returns the next result. Its second return value is iterator.Done if there are no more results. Once Next returns Done, all subsequent calls will return Done.
func (*DatabaseIterator) PageInfo ¶
func (it *DatabaseIterator) PageInfo() *iterator.PageInfo
PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
type DatabaseRoleIterator ¶
type DatabaseRoleIterator struct { // Response is the raw response for the current page. // It must be cast to the RPC response type. // Calling Next() or InternalFetch() updates this value. Response interface{} // InternalFetch is for use by the Google Cloud Libraries only. // It is not part of the stable interface of this package. // // InternalFetch returns results from a single call to the underlying RPC. // The number of results is no greater than pageSize. // If there are no more results, nextPageToken is empty and err is nil. InternalFetch func(pageSize int, pageToken string) (results []*databasepb.DatabaseRole, nextPageToken string, err error) // contains filtered or unexported fields }
DatabaseRoleIterator manages a stream of *databasepb.DatabaseRole.
func (*DatabaseRoleIterator) All ¶
func (it *DatabaseRoleIterator) All() iter.Seq2[*databasepb.DatabaseRole, error]
All returns an iterator. If an error is returned by the iterator, the iterator will stop after that iteration.
func (*DatabaseRoleIterator) Next ¶
func (it *DatabaseRoleIterator) Next() (*databasepb.DatabaseRole, error)
Next returns the next result. Its second return value is iterator.Done if there are no more results. Once Next returns Done, all subsequent calls will return Done.
func (*DatabaseRoleIterator) PageInfo ¶
func (it *DatabaseRoleIterator) PageInfo() *iterator.PageInfo
PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
type OperationIterator ¶
type OperationIterator struct { // Response is the raw response for the current page. // It must be cast to the RPC response type. // Calling Next() or InternalFetch() updates this value. Response interface{} // InternalFetch is for use by the Google Cloud Libraries only. // It is not part of the stable interface of this package. // // InternalFetch returns results from a single call to the underlying RPC. // The number of results is no greater than pageSize. // If there are no more results, nextPageToken is empty and err is nil. InternalFetch func(pageSize int, pageToken string) (results []*longrunningpb.Operation, nextPageToken string, err error) // contains filtered or unexported fields }
OperationIterator manages a stream of *longrunningpb.Operation.
func (*OperationIterator) All ¶
func (it *OperationIterator) All() iter.Seq2[*longrunningpb.Operation, error]
All returns an iterator. If an error is returned by the iterator, the iterator will stop after that iteration.
func (*OperationIterator) Next ¶
func (it *OperationIterator) Next() (*longrunningpb.Operation, error)
Next returns the next result. Its second return value is iterator.Done if there are no more results. Once Next returns Done, all subsequent calls will return Done.
func (*OperationIterator) PageInfo ¶
func (it *OperationIterator) PageInfo() *iterator.PageInfo
PageInfo supports pagination. See the google.golang.org/api/iterator package for details.
type RestoreDatabaseOperation ¶
type RestoreDatabaseOperation struct {
// contains filtered or unexported fields
}
RestoreDatabaseOperation manages a long-running operation from RestoreDatabase.
func (*RestoreDatabaseOperation) Done ¶
func (op *RestoreDatabaseOperation) Done() bool
Done reports whether the long-running operation has completed.
func (*RestoreDatabaseOperation) Metadata ¶
func (op *RestoreDatabaseOperation) Metadata() (*databasepb.RestoreDatabaseMetadata, error)
Metadata returns metadata associated with the long-running operation. Metadata itself does not contact the server, but Poll does. To get the latest metadata, call this method after a successful call to Poll. If the metadata is not available, the returned metadata and error are both nil.
func (*RestoreDatabaseOperation) Name ¶
func (op *RestoreDatabaseOperation) Name() string
Name returns the name of the long-running operation. The name is assigned by the server and is unique within the service from which the operation is created.
func (*RestoreDatabaseOperation) Poll ¶
func (op *RestoreDatabaseOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*databasepb.Database, error)
Poll fetches the latest state of the long-running operation.
Poll also fetches the latest metadata, which can be retrieved by Metadata.
If Poll fails, the error is returned and op is unmodified. If Poll succeeds and the operation has completed with failure, the error is returned and op.Done will return true. If Poll succeeds and the operation has completed successfully, op.Done will return true, and the response of the operation is returned. If Poll succeeds and the operation has not completed, the returned response and error are both nil.
func (*RestoreDatabaseOperation) Wait ¶
func (op *RestoreDatabaseOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*databasepb.Database, error)
Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
See documentation of Poll for error-handling information.
type UpdateDatabaseDdlOperation ¶
type UpdateDatabaseDdlOperation struct {
// contains filtered or unexported fields
}
UpdateDatabaseDdlOperation manages a long-running operation from UpdateDatabaseDdl.
func (*UpdateDatabaseDdlOperation) Done ¶
func (op *UpdateDatabaseDdlOperation) Done() bool
Done reports whether the long-running operation has completed.
func (*UpdateDatabaseDdlOperation) Metadata ¶
func (op *UpdateDatabaseDdlOperation) Metadata() (*databasepb.UpdateDatabaseDdlMetadata, error)
Metadata returns metadata associated with the long-running operation. Metadata itself does not contact the server, but Poll does. To get the latest metadata, call this method after a successful call to Poll. If the metadata is not available, the returned metadata and error are both nil.
func (*UpdateDatabaseDdlOperation) Name ¶
func (op *UpdateDatabaseDdlOperation) Name() string
Name returns the name of the long-running operation. The name is assigned by the server and is unique within the service from which the operation is created.
func (*UpdateDatabaseDdlOperation) Poll ¶
func (op *UpdateDatabaseDdlOperation) Poll(ctx context.Context, opts ...gax.CallOption) error
Poll fetches the latest state of the long-running operation.
Poll also fetches the latest metadata, which can be retrieved by Metadata.
If Poll fails, the error is returned and op is unmodified. If Poll succeeds and the operation has completed with failure, the error is returned and op.Done will return true. If Poll succeeds and the operation has completed successfully, op.Done will return true, and the response of the operation is returned. If Poll succeeds and the operation has not completed, the returned response and error are both nil.
func (*UpdateDatabaseDdlOperation) Wait ¶
func (op *UpdateDatabaseDdlOperation) Wait(ctx context.Context, opts ...gax.CallOption) error
Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
See documentation of Poll for error-handling information.
type UpdateDatabaseOperation ¶
type UpdateDatabaseOperation struct {
// contains filtered or unexported fields
}
UpdateDatabaseOperation manages a long-running operation from UpdateDatabase.
func (*UpdateDatabaseOperation) Done ¶
func (op *UpdateDatabaseOperation) Done() bool
Done reports whether the long-running operation has completed.
func (*UpdateDatabaseOperation) Metadata ¶
func (op *UpdateDatabaseOperation) Metadata() (*databasepb.UpdateDatabaseMetadata, error)
Metadata returns metadata associated with the long-running operation. Metadata itself does not contact the server, but Poll does. To get the latest metadata, call this method after a successful call to Poll. If the metadata is not available, the returned metadata and error are both nil.
func (*UpdateDatabaseOperation) Name ¶
func (op *UpdateDatabaseOperation) Name() string
Name returns the name of the long-running operation. The name is assigned by the server and is unique within the service from which the operation is created.
func (*UpdateDatabaseOperation) Poll ¶
func (op *UpdateDatabaseOperation) Poll(ctx context.Context, opts ...gax.CallOption) (*databasepb.Database, error)
Poll fetches the latest state of the long-running operation.
Poll also fetches the latest metadata, which can be retrieved by Metadata.
If Poll fails, the error is returned and op is unmodified. If Poll succeeds and the operation has completed with failure, the error is returned and op.Done will return true. If Poll succeeds and the operation has completed successfully, op.Done will return true, and the response of the operation is returned. If Poll succeeds and the operation has not completed, the returned response and error are both nil.
func (*UpdateDatabaseOperation) Wait ¶
func (op *UpdateDatabaseOperation) Wait(ctx context.Context, opts ...gax.CallOption) (*databasepb.Database, error)
Wait blocks until the long-running operation is completed, returning the response and any errors encountered.
See documentation of Poll for error-handling information.
Source Files ¶
auxiliary.go auxiliary_go123.go backup.go database.go database_admin_client.go doc.go helpers.go init.go path_funcs.go version.go
Directories ¶
Path | Synopsis |
---|---|
admin/database/apiv1/databasepb |
- Version
- v1.76.1 (latest)
- Published
- Feb 21, 2025
- Platform
- linux/amd64
- Imports
- 37 packages
- Last checked
- 11 hours ago –
Tools for package owners.