Documentation
¶
Overview ¶
Package adapter is an auto-generated package for the Cloud Spanner API.
Cloud Spanner is a managed, mission-critical, globally consistent and scalable relational database service.
NOTE: This package is in beta. It is not stable, and may be subject to changes.
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/adapter/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 := adapter.NewClient(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.
Use of Context ¶
The ctx passed to NewClient 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.
Index ¶
- func DefaultAuthScopes() []string
- type CallOptions
- type Client
- func (c *Client) AdaptMessage(ctx context.Context, req *adapterpb.AdaptMessageRequest, ...) (adapterpb.Adapter_AdaptMessageClient, error)
- func (c *Client) Close() error
- func (c *Client) Connection() *grpc.ClientConndeprecated
- func (c *Client) CreateSession(ctx context.Context, req *adapterpb.CreateSessionRequest, ...) (*adapterpb.Session, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultAuthScopes ¶
func DefaultAuthScopes() []string
DefaultAuthScopes reports the default set of authentication scopes to use with this package.
Types ¶
type CallOptions ¶
type CallOptions struct { CreateSession []gax.CallOption AdaptMessage []gax.CallOption }
CallOptions contains the retry settings for each method of Client.
type Client ¶
type Client struct { // The call options for this service. CallOptions *CallOptions // contains filtered or unexported fields }
Client 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 Adapter API ¶
The Cloud Spanner Adapter service allows native drivers of supported database dialects to interact directly with Cloud Spanner by wrapping the underlying wire protocol used by the driver in a gRPC stream.
func NewClient ¶
NewClient creates a new adapter client based on gRPC. The returned client must be Closed when it is done being used to clean up its underlying connections.
Cloud Spanner Adapter API ¶
The Cloud Spanner Adapter service allows native drivers of supported database dialects to interact directly with Cloud Spanner by wrapping the underlying wire protocol used by the driver in a gRPC stream.
Example ¶
package main import ( "context" adapter "cloud.google.com/go/spanner/adapter/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 := adapter.NewClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() // TODO: Use client. _ = c }
Output:
func NewRESTClient ¶
NewRESTClient creates a new adapter rest client.
Cloud Spanner Adapter API ¶
The Cloud Spanner Adapter service allows native drivers of supported database dialects to interact directly with Cloud Spanner by wrapping the underlying wire protocol used by the driver in a gRPC stream.
Example ¶
package main import ( "context" adapter "cloud.google.com/go/spanner/adapter/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 := adapter.NewRESTClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() // TODO: Use client. _ = c }
Output:
func (*Client) AdaptMessage ¶
func (c *Client) AdaptMessage(ctx context.Context, req *adapterpb.AdaptMessageRequest, opts ...gax.CallOption) (adapterpb.Adapter_AdaptMessageClient, error)
AdaptMessage handles a single message from the client and returns the result as a stream. The server will interpret the message frame and respond with message frames to the client.
func (*Client) Close ¶
Close closes the connection to the API service. The user should invoke this when the client is no longer required.
func (*Client) Connection
deprecated
func (c *Client) 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 (*Client) CreateSession ¶
func (c *Client) CreateSession(ctx context.Context, req *adapterpb.CreateSessionRequest, opts ...gax.CallOption) (*adapterpb.Session, error)
CreateSession creates a new session to be used for requests made by the adapter. A session identifies a specific incarnation of a database resource and is meant to be reused across many AdaptMessage calls.
Example ¶
package main import ( "context" adapter "cloud.google.com/go/spanner/adapter/apiv1" adapterpb "cloud.google.com/go/spanner/adapter/apiv1/adapterpb" ) 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 := adapter.NewClient(ctx) if err != nil { // TODO: Handle error. } defer c.Close() req := &adapterpb.CreateSessionRequest{ // TODO: Fill request struct fields. // See https://pkg.go.dev/cloud.google.com/go/spanner/adapter/apiv1/adapterpb#CreateSessionRequest. } resp, err := c.CreateSession(ctx, req) if err != nil { // TODO: Handle error. } // TODO: Use resp. _ = resp }
Output: