Cloud Spanner API v1 - Package cloud.google.com/go/spanner/admin/database/apiv1 (v1.83.0)

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:

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.

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.

Functions

func DatabaseAdminDatabasePath (deprecated)

func DatabaseAdminDatabasePath(project, instance, database string) string

DatabaseAdminDatabasePath returns the path for the database resource.

Deprecated: Use

fmt.Sprintf("projects/%s/instances/%s/databases/%s", project, instance, database)

instead.

func DatabaseAdminInstancePath (deprecated)

func DatabaseAdminInstancePath(project, instance string) string

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.

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.

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

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.

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

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

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

Wait blocks until the long-running operation is completed, returning the response and any errors encountered.

See documentation of Poll for error-handling information.

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

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

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

Wait blocks until the long-running operation is completed, returning the response and any errors encountered.

See documentation of Poll for error-handling information.

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

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

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

Wait blocks until the long-running operation is completed, returning the response and any errors encountered.

See documentation of Poll for error-handling information.

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.

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

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

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

AddSplitPoints adds split points to specified tables, indexes of a database.

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

CancelOperation is a utility method from google.longrunning.Operations.

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 (deprecated)

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

CopyBackup starts copying a Cloud Spanner Backup. The returned backup [long-running operation][google.longrunning.Operation] will have a name of the format projects/

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

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/

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

CreateBackupSchedule creates a new backup schedule.

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.