ydb

package module
v3.19.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2022 License: Apache-2.0 Imports: 42 Imported by: 108

README

ydb-go-sdk

PkgGoDev GoDoc tests lint Go Report Card codecov

YDB native Go's driver.

Supports table, discovery, coordination, ratelimiter, scheme and scripting clients for YDB.

import (
  "github.com/ydb-platform/ydb-go-sdk/v3"
  "github.com/ydb-platform/ydb-go-sdk/v3/table"
  "github.com/ydb-platform/ydb-go-sdk/v3/table/result/named"
  "github.com/ydb-platform/ydb-go-sdk/v3/table/types"
)

db, err := ydb.New(ctx,
  ydb.WithConnectionString("grpcs://localhost:2135/?database=/local"),
  ydb.WithAnonymousCredentials(),
)
if err != nil {
  log.Fatal(err)
}
defer func() { _ = db.Close(ctx) }()
err = db.Table().Do(
  ctx,
  func(ctx context.Context, s table.Session) (err error) {
    _, res, err := s.Execute(ctx,
      table.TxControl(
        table.BeginTx(table.WithSerializableReadWrite()), table.CommitTx(),
      ),
      "DECLARE $myStr AS Utf8; SELECT 42 as id, $myStr as myStr",
      table.NewQueryParameters(
        table.ValueParam("$myStr", types.UTF8Value("test")),
      ),
    )
    if err != nil {
      return err // for driver retry
    }
    defer func() { _ = res.Close() }()
    var (
      id    int32
      myStr *string //optional value
    )
    for res.NextResultSet(ctx) {
      for res.NextRow() {
        err := res.ScanNamed(
          named.Required("id", &id),
          named.Optional("myStr", &myStr),
        )
        if err != nil {
          return err
        }
        fmt.Printf("got id %v, got mystr: %v\n", id, *myStr)
      }
    }
    return res.Err()
  },
)
if err != nil {
  log.Fatal(err)
}

More examples of usage placed in examples repository.

See also CREDENTIALS.md about supported YDB credentials.

See DEBUG.md about supported debug tooling over ydb-go-sdk.

See ENVIRON.md about supported environment variables of ydb-go-sdk.

Documentation

Index

Constants

View Source
const Version = meta.Version

Version alias for except cycle import

Variables

This section is empty.

Functions

func IsOperationError

func IsOperationError(err error, codes ...Ydb.StatusIds_StatusCode) bool

func IsOperationErrorAlreadyExistsError added in v3.5.0

func IsOperationErrorAlreadyExistsError(err error) bool

func IsOperationErrorNotFoundError added in v3.5.0

func IsOperationErrorNotFoundError(err error) bool

func IsOperationErrorOverloaded added in v3.5.0

func IsOperationErrorOverloaded(err error) bool

func IsOperationErrorSchemeError added in v3.5.0

func IsOperationErrorSchemeError(err error) bool

func IsOperationErrorUnavailable added in v3.5.0

func IsOperationErrorUnavailable(err error) bool

func IsRatelimiterAcquireError added in v3.11.0

func IsRatelimiterAcquireError(err error) bool

func IsTimeoutError

func IsTimeoutError(err error) bool

func IsTransportError

func IsTransportError(err error, codes ...grpcCodes.Code) bool

func IsYdbError added in v3.4.2

func IsYdbError(err error) bool

func IterateByIssues

func IterateByIssues(err error, it func(message string, code Ydb.StatusIds_StatusCode, severity uint32))

func ToRatelimiterAcquireError added in v3.11.0

func ToRatelimiterAcquireError(err error) ratelimiter.AcquireError

func WithOperationCancelAfter added in v3.18.0

func WithOperationCancelAfter(ctx context.Context, operationCancelAfter time.Duration) context.Context

WithOperationCancelAfter returns a copy of parent context in which YDB operation cancel after parameter is set to d. If parent context cancellation timeout is smaller than d, parent context is returned.

func WithOperationTimeout added in v3.18.0

func WithOperationTimeout(ctx context.Context, operationTimeout time.Duration) context.Context

WithOperationTimeout returns a copy of parent context in which YDB operation timeout parameter is set to d. If parent context timeout is smaller than d, parent context is returned.

func WithRequestType added in v3.13.0

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

WithRequestType returns a copy of parent context with custom request type

func WithTraceID added in v3.13.0

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

WithTraceID returns a copy of parent context with traceID

Types

type Connection

type Connection interface {
	closer.Closer
	database.Info
	grpc.ClientConnInterface

	// Table returns table client
	Table() table.Client

	// Scheme returns scheme client
	Scheme() scheme.Client

	// Coordination returns coordination client
	Coordination() coordination.Client

	// Ratelimiter returns rate limiter client
	Ratelimiter() ratelimiter.Client

	// Discovery returns discovery client
	Discovery() discovery.Client

	// Scripting returns scripting client
	Scripting() scripting.Client

	// With returns Connection specified with custom options
	// Options provide options replacement for all clients taked from new Connection
	With(ctx context.Context, opts ...Option) (Connection, error)
}

Connection interface provide access to YDB service clients Interface and list of clients may be changed in the future

func New

func New(ctx context.Context, opts ...Option) (_ Connection, err error)

New connects to name and return name runtime holder

type Error added in v3.4.2

type Error xerrors.Error

func OperationError added in v3.16.9

func OperationError(err error) Error

func TransportError added in v3.16.9

func TransportError(err error) Error

type LoggerOption added in v3.5.3

type LoggerOption logger.Option

func WithErrWriter added in v3.5.0

func WithErrWriter(err io.Writer) LoggerOption

func WithExternalLogger added in v3.5.0

func WithExternalLogger(external log.Logger) LoggerOption

func WithMinLevel added in v3.3.0

func WithMinLevel(minLevel log.Level) LoggerOption

func WithNamespace added in v3.3.0

func WithNamespace(namespace string) LoggerOption

func WithNoColor added in v3.3.0

func WithNoColor(b bool) LoggerOption

func WithOutWriter added in v3.5.0

func WithOutWriter(out io.Writer) LoggerOption

type Option

type Option func(ctx context.Context, c *connection) error

func MergeOptions added in v3.5.1

func MergeOptions(opts ...Option) Option

func With

func With(options ...config.Option) Option

func WithAccessTokenCredentials

func WithAccessTokenCredentials(accessToken string) Option

func WithAnonymousCredentials

func WithAnonymousCredentials() Option

func WithBalancer added in v3.6.0

func WithBalancer(balancer balancer.Balancer) Option

func WithCertificate

func WithCertificate(cert *x509.Certificate) Option

func WithCertificatesFromFile

func WithCertificatesFromFile(caFile string) Option

func WithCertificatesFromPem

func WithCertificatesFromPem(bytes []byte) Option

func WithConnectionString

func WithConnectionString(connectionString string) Option

WithConnectionString accept connection string like 'grpc[s]://{endpoint}/?database={database}' Warning: WithConnectionString will be removed at next major release (connection string will be required string param of ydb.New)

func WithConnectionTTL added in v3.7.0

func WithConnectionTTL(ttl time.Duration) Option

WithConnectionTTL defines duration for parking idle connections Warning: if defined WithSessionPoolIdleThreshold - idleThreshold must be less than connectionTTL

func WithCreateCredentialsFunc

func WithCreateCredentialsFunc(createCredentials func(ctx context.Context) (credentials.Credentials, error)) Option

func WithCredentials

func WithCredentials(c credentials.Credentials) Option

WithCredentials in conjunction with Connection.With function prohibit reuse of conn pool. Thus, Connection.With will effectively create totally separate Connection.

func WithDatabase added in v3.2.1

func WithDatabase(database string) Option

WithDatabase defines database option Deprecated: use WithConnectionString or dsn package instead

func WithDialTimeout

func WithDialTimeout(timeout time.Duration) Option

func WithDiscoveryInterval

func WithDiscoveryInterval(discoveryInterval time.Duration) Option

func WithEndpoint added in v3.2.1

func WithEndpoint(endpoint string) Option

WithEndpoint defines endpoint option Deprecated: use WithConnectionString or dsn package instead

func WithInsecure added in v3.8.6

func WithInsecure() Option

WithInsecure defines secure option Deprecated: use WithConnectionString or dsn package instead

func WithLogger added in v3.3.0

func WithLogger(details trace.Details, opts ...LoggerOption) Option

func WithMinTLSVersion added in v3.9.1

func WithMinTLSVersion(minVersion uint16) Option

func WithPanicCallback added in v3.17.0

func WithPanicCallback(panicCallback func(e interface{})) Option

WithPanicCallback specified behavior on panic Warning: WithPanicCallback must be defined on start of all options (before `WithTrace{Driver,Table,Scheme,Scripting,Coordination,Ratelimiter}` and other options) If not defined - panic would not intercept with driver

func WithRatelimiterOptions added in v3.11.0

func WithRatelimiterOptions(opts ...ratelimiterConfig.Option) Option

func WithRequestsType added in v3.13.0

func WithRequestsType(requestsType string) Option

func WithSecure added in v3.7.0

func WithSecure(secure bool) Option

WithSecure defines secure option Deprecated: use WithConnectionString or dsn package instead

func WithSessionPoolCreateSessionTimeout

func WithSessionPoolCreateSessionTimeout(createSessionTimeout time.Duration) Option

func WithSessionPoolDeleteTimeout

func WithSessionPoolDeleteTimeout(deleteTimeout time.Duration) Option

func WithSessionPoolIdleThreshold

func WithSessionPoolIdleThreshold(idleThreshold time.Duration) Option

WithSessionPoolIdleThreshold defines keep-alive interval for idle sessions Warning: if defined WithConnectionTTL - idleThreshold must be less than connectionTTL

func WithSessionPoolKeepAliveMinSize

func WithSessionPoolKeepAliveMinSize(keepAliveMinSize int) Option

func WithSessionPoolKeepAliveTimeout

func WithSessionPoolKeepAliveTimeout(keepAliveTimeout time.Duration) Option

func WithSessionPoolSizeLimit

func WithSessionPoolSizeLimit(sizeLimit int) Option

func WithTLSSInsecureSkipVerify added in v3.11.0

func WithTLSSInsecureSkipVerify() Option

func WithTableConfigOption

func WithTableConfigOption(option tableConfig.Option) Option

func WithTraceCoordination added in v3.10.0

func WithTraceCoordination(t trace.Coordination, opts ...trace.CoordinationComposeOption) Option

WithTraceCoordination returns coordination trace option

func WithTraceDiscovery added in v3.10.0

func WithTraceDiscovery(t trace.Discovery, opts ...trace.DiscoveryComposeOption) Option

WithTraceDiscovery returns discovery trace option

func WithTraceDriver

func WithTraceDriver(trace trace.Driver, opts ...trace.DriverComposeOption) Option

WithTraceDriver returns deadline which has associated Driver with it.

func WithTraceRatelimiter added in v3.10.0

func WithTraceRatelimiter(t trace.Ratelimiter, opts ...trace.RatelimiterComposeOption) Option

WithTraceRatelimiter returns ratelimiter trace option

func WithTraceScheme added in v3.10.0

func WithTraceScheme(t trace.Scheme, opts ...trace.SchemeComposeOption) Option

WithTraceScheme returns scheme trace option

func WithTraceScripting added in v3.10.0

func WithTraceScripting(t trace.Scripting, opts ...trace.ScriptingComposeOption) Option

WithTraceScripting scripting trace option

func WithTraceTable

func WithTraceTable(t trace.Table, opts ...trace.TableComposeOption) Option

WithTraceTable returns table trace option

func WithUserAgent added in v3.7.0

func WithUserAgent(userAgent string) Option

Jump to

Keyboard shortcuts

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