Documentation ¶
Overview ¶
Example (ConsumedUnitsCount) ¶
ctx := context.TODO() db, err := ydb.Open(ctx, "grpc://localhost:2136/local") if err != nil { log.Fatal(err) } defer db.Close(ctx) // cleanup resources var ( query = `SELECT 42 as id, "my string" as myStr` id int32 // required value myStr string // optional value totalConsumedUnits uint64 ) err = db.Table().Do( // Do retry operation on errors with best effort meta.WithTrailerCallback(ctx, func(md metadata.MD) { totalConsumedUnits += meta.ConsumedUnits(md) }), func(ctx context.Context, s table.Session) (err error) { // retry operation _, res, err := s.Execute(ctx, table.DefaultTxControl(), query, nil) if err != nil { return err // for auto-retry with driver } defer res.Close() // cleanup resources if err = res.NextResultSetErr(ctx); err != nil { // check single result set and switch to it return err // for auto-retry with driver } for res.NextRow() { // iterate over rows err = res.ScanNamed( named.Required("id", &id), named.OptionalWithDefault("myStr", &myStr), ) if err != nil { return err // generally scan error not retryable, return it for driver check error } log.Printf("id=%v, myStr='%s'\n", id, myStr) } return res.Err() // return finally result error for auto-retry with driver }, table.WithIdempotent(), ) if err != nil { log.Printf("unexpected error: %v", err) } log.Println("total consumed units:", totalConsumedUnits)
Output:
Index ¶
- func ConsumedUnits(md metadata.MD) (consumedUnits uint64)
- func WithAllowFeatures(ctx context.Context, features ...string) context.Context
- func WithApplicationName(ctx context.Context, applicationName string) context.Context
- func WithRequestType(ctx context.Context, requestType string) context.Context
- func WithTraceID(ctx context.Context, traceID string) context.Context
- func WithTrailerCallback(ctx context.Context, callback func(md metadata.MD)) context.Context
- func WithUserAgent(ctx context.Context, _ string) context.Contextdeprecated
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ConsumedUnits ¶
func WithAllowFeatures ¶
WithAllowFeatures returns a copy of parent context with allowed client feature
func WithApplicationName ¶
WithApplicationName returns a copy of parent context with application name
func WithRequestType ¶
WithRequestType returns a copy of parent context with custom request type
func WithTraceID ¶
WithTraceID returns a copy of parent context with traceID
func WithTrailerCallback ¶
WithTrailerCallback attaches callback to context for listening incoming metadata
func WithUserAgent
deprecated
WithUserAgent returns a copy of parent context with custom user-agent info
Deprecated: use WithApplicationName instead. Will be removed after Oct 2024. Read about versioning policy: https://github.com/ydb-platform/ydb-go-sdk/blob/master/VERSIONING.md#deprecated
Types ¶
This section is empty.