meta

package
v3.80.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 25, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

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

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConsumedUnits

func ConsumedUnits(md metadata.MD) (consumedUnits uint64)

func WithAllowFeatures

func WithAllowFeatures(ctx context.Context, features ...string) context.Context

WithAllowFeatures returns a copy of parent context with allowed client feature

func WithApplicationName

func WithApplicationName(ctx context.Context, applicationName string) context.Context

WithApplicationName returns a copy of parent context with application name

func WithRequestType

func WithRequestType(ctx context.Context, requestType string) context.Context

WithRequestType returns a copy of parent context with custom request type

func WithTraceID

func WithTraceID(ctx context.Context, traceID string) context.Context

WithTraceID returns a copy of parent context with traceID

func WithTrailerCallback

func WithTrailerCallback(
	ctx context.Context,
	callback func(md metadata.MD),
) context.Context

WithTrailerCallback attaches callback to context for listening incoming metadata

func WithUserAgent deprecated

func WithUserAgent(ctx context.Context, _ string) context.Context

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL