Documentation ¶
Overview ¶
Package database is an experimental, auto-generated package for the database API.
Index ¶
- func DatabaseAdminDatabasePath(project, instance, database string) string
- func DatabaseAdminInstancePath(project, instance string) string
- type DatabaseAdminCallOptions
- type DatabaseAdminClient
- func (c *DatabaseAdminClient) Close() error
- func (c *DatabaseAdminClient) Connection() *grpc.ClientConn
- func (c *DatabaseAdminClient) CreateDatabase(ctx context.Context, req *databasepb.CreateDatabaseRequest) (*DatabaseOperation, error)
- func (c *DatabaseAdminClient) DatabaseOperation(name string) *DatabaseOperation
- func (c *DatabaseAdminClient) DropDatabase(ctx context.Context, req *databasepb.DropDatabaseRequest) error
- func (c *DatabaseAdminClient) EmptyOperation(name string) *EmptyOperation
- func (c *DatabaseAdminClient) GetDatabase(ctx context.Context, req *databasepb.GetDatabaseRequest) (*databasepb.Database, error)
- func (c *DatabaseAdminClient) GetDatabaseDdl(ctx context.Context, req *databasepb.GetDatabaseDdlRequest) (*databasepb.GetDatabaseDdlResponse, error)
- func (c *DatabaseAdminClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest) (*iampb.Policy, error)
- func (c *DatabaseAdminClient) ListDatabases(ctx context.Context, req *databasepb.ListDatabasesRequest) *DatabaseIterator
- func (c *DatabaseAdminClient) SetGoogleClientInfo(keyval ...string)
- func (c *DatabaseAdminClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest) (*iampb.Policy, error)
- func (c *DatabaseAdminClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest) (*iampb.TestIamPermissionsResponse, error)
- func (c *DatabaseAdminClient) UpdateDatabaseDdl(ctx context.Context, req *databasepb.UpdateDatabaseDdlRequest) (*EmptyOperation, error)
- type DatabaseIterator
- type DatabaseOperation
- func (op *DatabaseOperation) Done() bool
- func (op *DatabaseOperation) Metadata() (*databasepb.CreateDatabaseMetadata, error)
- func (op *DatabaseOperation) Name() string
- func (op *DatabaseOperation) Poll(ctx context.Context) (*databasepb.Database, error)
- func (op *DatabaseOperation) Wait(ctx context.Context) (*databasepb.Database, error)
- type EmptyOperation
Examples ¶
- DatabaseAdminClient.CreateDatabase
- DatabaseAdminClient.DropDatabase
- DatabaseAdminClient.GetDatabase
- DatabaseAdminClient.GetDatabaseDdl
- DatabaseAdminClient.GetIamPolicy
- DatabaseAdminClient.ListDatabases
- DatabaseAdminClient.SetIamPolicy
- DatabaseAdminClient.TestIamPermissions
- DatabaseAdminClient.UpdateDatabaseDdl
- NewDatabaseAdminClient
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DatabaseAdminDatabasePath ¶
DatabaseAdminDatabasePath returns the path for the database resource.
func DatabaseAdminInstancePath ¶
DatabaseAdminInstancePath returns the path for the instance resource.
Types ¶
type DatabaseAdminCallOptions ¶
type DatabaseAdminCallOptions struct { ListDatabases []gax.CallOption CreateDatabase []gax.CallOption GetDatabase []gax.CallOption UpdateDatabaseDdl []gax.CallOption DropDatabase []gax.CallOption GetDatabaseDdl []gax.CallOption SetIamPolicy []gax.CallOption GetIamPolicy []gax.CallOption TestIamPermissions []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 // contains filtered or unexported fields }
DatabaseAdminClient is a client for interacting with Cloud Spanner Database Admin API.
func NewDatabaseAdminClient ¶
func NewDatabaseAdminClient(ctx context.Context, opts ...option.ClientOption) (*DatabaseAdminClient, error)
NewDatabaseAdminClient creates a new database admin client.
Cloud Spanner Database Admin API ¶
The Cloud Spanner Database Admin API can be used to create, drop, and list databases. It also enables updating the schema of pre-existing databases.
Example ¶
ctx := context.Background() c, err := database.NewDatabaseAdminClient(ctx) if err != nil { // TODO: Handle error. } // TODO: Use client. _ = c
Output:
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 the client's connection to the API service.
func (*DatabaseAdminClient) CreateDatabase ¶
func (c *DatabaseAdminClient) CreateDatabase(ctx context.Context, req *databasepb.CreateDatabaseRequest) (*DatabaseOperation, 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[google.longrunning.Operation.metadata] field type is [CreateDatabaseMetadata][google.spanner.admin.database.v1.CreateDatabaseMetadata]. The [response][google.longrunning.Operation.response] field type is [Database][google.spanner.admin.database.v1.Database], if successful.
Example ¶
ctx := context.Background() c, err := database.NewDatabaseAdminClient(ctx) if err != nil { // TODO: Handle error. } req := &databasepb.CreateDatabaseRequest{ // TODO: Fill request struct fields. } 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
Output:
func (*DatabaseAdminClient) DatabaseOperation ¶
func (c *DatabaseAdminClient) DatabaseOperation(name string) *DatabaseOperation
DatabaseOperation returns a new DatabaseOperation from a given name. The name must be that of a previously created DatabaseOperation, possibly from a different process.
func (*DatabaseAdminClient) DropDatabase ¶
func (c *DatabaseAdminClient) DropDatabase(ctx context.Context, req *databasepb.DropDatabaseRequest) error
DropDatabase drops (aka deletes) a Cloud Spanner database.
Example ¶
ctx := context.Background() c, err := database.NewDatabaseAdminClient(ctx) if err != nil { // TODO: Handle error. } req := &databasepb.DropDatabaseRequest{ // TODO: Fill request struct fields. } err = c.DropDatabase(ctx, req) if err != nil { // TODO: Handle error. }
Output:
func (*DatabaseAdminClient) EmptyOperation ¶
func (c *DatabaseAdminClient) EmptyOperation(name string) *EmptyOperation
EmptyOperation returns a new EmptyOperation from a given name. The name must be that of a previously created EmptyOperation, possibly from a different process.
func (*DatabaseAdminClient) GetDatabase ¶
func (c *DatabaseAdminClient) GetDatabase(ctx context.Context, req *databasepb.GetDatabaseRequest) (*databasepb.Database, error)
GetDatabase gets the state of a Cloud Spanner database.
Example ¶
ctx := context.Background() c, err := database.NewDatabaseAdminClient(ctx) if err != nil { // TODO: Handle error. } req := &databasepb.GetDatabaseRequest{ // TODO: Fill request struct fields. } resp, err := c.GetDatabase(ctx, req) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp
Output:
func (*DatabaseAdminClient) GetDatabaseDdl ¶
func (c *DatabaseAdminClient) GetDatabaseDdl(ctx context.Context, req *databasepb.GetDatabaseDdlRequest) (*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][google.longrunning.Operations] API.
Example ¶
ctx := context.Background() c, err := database.NewDatabaseAdminClient(ctx) if err != nil { // TODO: Handle error. } req := &databasepb.GetDatabaseDdlRequest{ // TODO: Fill request struct fields. } resp, err := c.GetDatabaseDdl(ctx, req) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp
Output:
func (*DatabaseAdminClient) GetIamPolicy ¶
func (c *DatabaseAdminClient) GetIamPolicy(ctx context.Context, req *iampb.GetIamPolicyRequest) (*iampb.Policy, error)
GetIamPolicy gets the access control policy for a database resource. Returns an empty policy if a database exists but does not have a policy set.
Authorization requires `spanner.databases.getIamPolicy` permission on [resource][google.iam.v1.GetIamPolicyRequest.resource].
Example ¶
ctx := context.Background() c, err := database.NewDatabaseAdminClient(ctx) if err != nil { // TODO: Handle error. } req := &iampb.GetIamPolicyRequest{ // TODO: Fill request struct fields. } resp, err := c.GetIamPolicy(ctx, req) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp
Output:
func (*DatabaseAdminClient) ListDatabases ¶
func (c *DatabaseAdminClient) ListDatabases(ctx context.Context, req *databasepb.ListDatabasesRequest) *DatabaseIterator
ListDatabases lists Cloud Spanner databases.
Example ¶
ctx := context.Background() c, err := database.NewDatabaseAdminClient(ctx) if err != nil { // TODO: Handle error. } req := &databasepb.ListDatabasesRequest{ // TODO: Fill request struct fields. } it := c.ListDatabases(ctx, req) for { resp, err := it.Next() if err != nil { // TODO: Handle error. break } // TODO: Use resp. _ = resp }
Output:
func (*DatabaseAdminClient) SetGoogleClientInfo ¶
func (c *DatabaseAdminClient) SetGoogleClientInfo(keyval ...string)
SetGoogleClientInfo sets the name and version of the application in the `x-goog-api-client` header passed on each request. Intended for use by Google-written clients.
func (*DatabaseAdminClient) SetIamPolicy ¶
func (c *DatabaseAdminClient) SetIamPolicy(ctx context.Context, req *iampb.SetIamPolicyRequest) (*iampb.Policy, error)
SetIamPolicy sets the access control policy on a database resource. Replaces any existing policy.
Authorization requires `spanner.databases.setIamPolicy` permission on [resource][google.iam.v1.SetIamPolicyRequest.resource].
Example ¶
ctx := context.Background() c, err := database.NewDatabaseAdminClient(ctx) if err != nil { // TODO: Handle error. } req := &iampb.SetIamPolicyRequest{ // TODO: Fill request struct fields. } resp, err := c.SetIamPolicy(ctx, req) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp
Output:
func (*DatabaseAdminClient) TestIamPermissions ¶
func (c *DatabaseAdminClient) TestIamPermissions(ctx context.Context, req *iampb.TestIamPermissionsRequest) (*iampb.TestIamPermissionsResponse, error)
TestIamPermissions returns permissions that the caller has on the specified database 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.
Example ¶
ctx := context.Background() c, err := database.NewDatabaseAdminClient(ctx) if err != nil { // TODO: Handle error. } req := &iampb.TestIamPermissionsRequest{ // TODO: Fill request struct fields. } resp, err := c.TestIamPermissions(ctx, req) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp
Output:
func (*DatabaseAdminClient) UpdateDatabaseDdl ¶
func (c *DatabaseAdminClient) UpdateDatabaseDdl(ctx context.Context, req *databasepb.UpdateDatabaseDdlRequest) (*EmptyOperation, 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[google.longrunning.Operation.metadata] field type is [UpdateDatabaseDdlMetadata][google.spanner.admin.database.v1.UpdateDatabaseDdlMetadata]. The operation has no response.
Example ¶
ctx := context.Background() c, err := database.NewDatabaseAdminClient(ctx) if err != nil { // TODO: Handle error. } req := &databasepb.UpdateDatabaseDdlRequest{ // TODO: Fill request struct fields. } op, err := c.UpdateDatabaseDdl(ctx, req) if err != nil { // TODO: Handle error. } err = op.Wait(ctx) // TODO: Handle error.
Output:
type DatabaseIterator ¶
type DatabaseIterator struct { // 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) 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 DatabaseOperation ¶
type DatabaseOperation struct {
// contains filtered or unexported fields
}
DatabaseOperation manages a long-running operation yielding databasepb.Database.
func (*DatabaseOperation) Done ¶
func (op *DatabaseOperation) Done() bool
Done reports whether the long-running operation has completed.
func (*DatabaseOperation) Metadata ¶
func (op *DatabaseOperation) 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 (*DatabaseOperation) Name ¶
func (op *DatabaseOperation) 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 (*DatabaseOperation) Poll ¶
func (op *DatabaseOperation) Poll(ctx context.Context) (*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 (*DatabaseOperation) Wait ¶
func (op *DatabaseOperation) Wait(ctx context.Context) (*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 EmptyOperation ¶
type EmptyOperation struct {
// contains filtered or unexported fields
}
EmptyOperation manages a long-running operation with no result.
func (*EmptyOperation) Done ¶
func (op *EmptyOperation) Done() bool
Done reports whether the long-running operation has completed.
func (*EmptyOperation) Metadata ¶
func (op *EmptyOperation) 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 (*EmptyOperation) Name ¶
func (op *EmptyOperation) 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 (*EmptyOperation) Poll ¶
func (op *EmptyOperation) Poll(ctx context.Context) 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.