ydb-go-sdk
- native Go's driver for YDB.
Supports table
, discovery
, coordination
, ratelimiter
, scheme
and scripting
clients for YDB
.
YDB
is an open-source Distributed SQL Database that combines high availability and scalability with strict consistency and ACID transactions.
- connect to YDB
db, err := ydb.Open(ctx, "grpcs://localhost:2135/?database=/local")
if err != nil {
log.Fatal(err)
}
- execute
SELECT
query
const query = `SELECT 42 as id, "myStr" as myStr;`
// Do retry operation on errors with best effort
queryErr := db.Table().Do(ctx, func(ctx context.Context, s table.Session) (err error) {
_, res, err := s.Execute(ctx, table.DefaultTxControl(), query, nil)
if err != nil {
return err
}
defer res.Close()
if err = res.NextResultSetErr(ctx); err != nil {
return err
}
for res.NextRow() {
var id int32
var myStr string
err = res.ScanNamed(named.Required("id", &id),named.OptionalWithDefault("myStr", &myStr))
if err != nil {
log.Fatal(err)
}
log.Printf("id=%v, myStr='%s'\n", id, myStr)
}
return res.Err() // for driver retry if not nil
})
if queryErr != nil {
log.Fatal(queryErr)
}
More examples of usage placed in examples repository.
Driver contains two options for making simple credentials.Credentials
:
ydb.WithAnonymousCredentials()
ydb.WithAccessTokenCredentials("token")
Another variants of credentials.Credentials
object provides with external packages:
Package | Type | Description | Link of example usage |
---|---|---|---|
ydb-go-yc | credentials | credentials provider for Yandex.Cloud | yc.WithServiceAccountKeyFileCredentials yc.WithInternalCA yc.WithMetadataCredentials |
ydb-go-yc-metadata | credentials | metadata credentials provider for Yandex.Cloud | yc.WithInternalCA yc.WithCredentials |
ydb-go-sdk-auth-environ | credentials | create credentials from environ | ydbEnviron.WithEnvironCredentials |
Package ydb-go-sdk
provide debugging over trace events in package trace
.
Next packages provide debug tooling:
Package | Type | Description | Link of example usage |
---|---|---|---|
ydb-go-sdk-zap | logging | logging ydb-go-sdk events with zap package | ydbZap.WithTraces |
ydb-go-sdk-zerolog | logging | logging ydb-go-sdk events with zerolog package | ydbZerolog.WithTraces |
ydb-go-sdk-metrics | metrics | common metrics of ydb-go-sdk. Package declare interfaces such as Registry , GaugeVec and Gauge and use it for traces |
|
ydb-go-sdk-prometheus | metrics | prometheus wrapper over ydb-go-sdk-metrics | ydbPrometheus.WithTraces |
ydb-go-sdk-opentracing | tracing | opentracing plugin for trace internal ydb-go-sdk calls | ydbOpentracing.WithTraces |
ydb-go-sdk
supports next environment variables which redefines default behavior of driver
Name | Type | Default | Description |
---|---|---|---|
YDB_SSL_ROOT_CERTIFICATES_FILE |
string |
path to certificates file | |
YDB_LOG_SEVERITY_LEVEL |
string |
quiet |
severity logging level of internal driver logger. Supported: trace , debug , info , warn , error , fatal , quiet |
YDB_LOG_NO_COLOR |
bool |
false |
set any non empty value to disable colouring logs with internal driver logger |
GRPC_GO_LOG_VERBOSITY_LEVEL |
integer |
set to 99 to see grpc logs |
|
GRPC_GO_LOG_SEVERITY_LEVEL |
string |
set to info to see grpc logs |