Skip to content

Commit a372f79

Browse files
committed
CHANGELOG.md
1 parent f54c60d commit a372f79

File tree

10 files changed

+106
-76
lines changed

10 files changed

+106
-76
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* Added `table.DefaultTxControl()` transaction control creator with serializable read-write isolation mode and auto-commit
2+
* Fixed passing nil query parameters
13
* Fixed locking of cluster during call `cluster.Get`
24

35
## v3.19.1

CREDENTIALS.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

DEBUG.md

Lines changed: 0 additions & 13 deletions
This file was deleted.

ENVIRON.md

Lines changed: 0 additions & 10 deletions
This file was deleted.

README.md

Lines changed: 84 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,96 @@
1-
# ydb-go-sdk
1+
# `ydb-go-sdk` - native Go's driver for [YDB](https://github.com/ydb-platform/ydb).
22

33
[![PkgGoDev](https://pkg.go.dev/badge/github.com/ydb-platform/ydb-go-sdk/v3)](https://pkg.go.dev/github.com/ydb-platform/ydb-go-sdk/v3)
4-
[![GoDoc](https://godoc.org/github.com/ydb-platform/ydb-go-sdk/v3?status.svg)](https://godoc.org/github.com/ydb-platform/ydb-go-sdk/v3)
54
![tests](https://github.com/ydb-platform/ydb-go-sdk/workflows/tests/badge.svg?branch=master)
65
![lint](https://github.com/ydb-platform/ydb-go-sdk/workflows/lint/badge.svg?branch=master)
76
[![Go Report Card](https://goreportcard.com/badge/github.com/ydb-platform/ydb-go-sdk/v3)](https://goreportcard.com/report/github.com/ydb-platform/ydb-go-sdk/v3)
87
[![codecov](https://codecov.io/gh/ydb-platform/ydb-go-sdk/branch/master/graph/badge.svg?precision=2)](https://app.codecov.io/gh/ydb-platform/ydb-go-sdk)
98

10-
[YDB](https://github.com/ydb-platform/ydb) native Go's driver.
9+
Supports `table`, `discovery`, `coordination`, `ratelimiter`, `scheme` and `scripting` clients for `YDB`.
10+
`YDB` is an open-source Distributed SQL Database that combines high availability and scalability with strict consistency and ACID transactions.
1111

12-
Supports `table`, `discovery`, `coordination`, `ratelimiter`, `scheme` and `scripting` clients for `YDB`.
12+
## Example Usage <a name="example"></a>
1313

14-
Simple example see in [example](example_table_test.go). More examples of usage placed in [examples](https://github.com/ydb-platform/ydb-go-examples) repository.
14+
* connect to YDB
15+
```
16+
db, err := ydb.New(ctx,
17+
ydb.WithConnectionString("grpcs://localhost:2135/?database=/local"),
18+
ydb.WithAnonymousCredentials(),
19+
)
20+
if err != nil {
21+
log.Fatal(err)
22+
}
23+
```
24+
* execute `SELECT` query
25+
```
26+
const query = `SELECT 42 as id, "myStr" as myStr;`
27+
28+
// Do retry operation on errors with best effort
29+
queryErr := db.Table().Do(ctx, func(ctx context.Context, s table.Session) (err error) {
30+
_, res, err := s.Execute(ctx, table.DefaultTxControl(), query, nil)
31+
if err != nil {
32+
return err
33+
}
34+
defer res.Close()
35+
if err = res.NextResultSetErr(ctx); err != nil {
36+
return err
37+
}
38+
for res.NextRow() {
39+
var id int32
40+
var myStr string
41+
err = res.ScanNamed(named.Required("id", &id),named.OptionalWithDefault("myStr", &myStr))
42+
if err != nil {
43+
log.Fatal(err)
44+
}
45+
log.Printf("id=%v, myStr='%s'\n", id, myStr)
46+
}
47+
return res.Err() // for driver retry if not nil
48+
})
49+
if queryErr != nil {
50+
log.Fatal(queryErr)
51+
}
52+
```
53+
More examples of usage placed in [examples](https://github.com/ydb-platform/ydb-go-examples) repository.
54+
55+
## Credentials <a name="credentials"></a>
56+
57+
Driver contains two options for making simple `credentials.Credentials`:
58+
- `ydb.WithAnonymousCredentials()`
59+
- `ydb.WithAccessTokenCredentials("token")`
60+
61+
Another variants of `credentials.Credentials` object provides with external packages:
62+
63+
Package | Type | Description | Link of example usage
64+
--- | --- |---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| ---
65+
[ydb-go-yc](https://github.com/ydb-platform/ydb-go-yc) | credentials | credentials provider for Yandex.Cloud | [yc.WithServiceAccountKeyFileCredentials](https://github.com/ydb-platform/ydb-go-yc/blob/master/internal/cmd/connect/main.go#L22)
66+
[yc.WithInternalCA](https://github.com/ydb-platform/ydb-go-yc/blob/master/internal/cmd/connect/main.go#L22) [yc.WithMetadataCredentials](https://github.com/ydb-platform/ydb-go-yc/blob/master/internal/cmd/connect/main.go#L24)
67+
[ydb-go-yc-metadata](https://github.com/ydb-platform/ydb-go-yc-metadata) | credentials | metadata credentials provider for Yandex.Cloud | [yc.WithInternalCA](https://github.com/ydb-platform/ydb-go-yc-metadata/blob/master/options.go#L23) [yc.WithCredentials](https://github.com/ydb-platform/ydb-go-yc-metadata/blob/master/options.go#L17)
68+
[ydb-go-sdk-auth-environ](https://github.com/ydb-platform/ydb-go-sdk-auth-environ) | credentials | create credentials from environ | [ydbEnviron.WithEnvironCredentials](https://github.com/ydb-platform/ydb-go-sdk-auth-environ/blob/master/env.go#L11)
69+
70+
## Ecosystem of debug tools over `ydb-go-sdk` <a name="debug"></a>
71+
72+
Package `ydb-go-sdk` provide debugging over trace events in package `trace`.
73+
Next packages provide debug tooling:
74+
75+
Package | Type | Description | Link of example usage
76+
--- | --- |---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| ---
77+
[ydb-go-sdk-zap](https://github.com/ydb-platform/ydb-go-sdk-zap) | logging | logging ydb-go-sdk events with zap package | [ydbZap.WithTraces](https://github.com/ydb-platform/ydb-go-sdk-zap/blob/master/internal/cmd/bench/main.go#L64)
78+
[ydb-go-sdk-zerolog](https://github.com/ydb-platform/ydb-go-sdk-zap) | logging | logging ydb-go-sdk events with zerolog package | [ydbZerolog.WithTraces](https://github.com/ydb-platform/ydb-go-sdk-zerolog/blob/master/internal/cmd/bench/main.go#L47)
79+
[ydb-go-sdk-metrics](https://github.com/ydb-platform/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 |
80+
[ydb-go-sdk-prometheus](https://github.com/ydb-platform/ydb-go-sdk-prometheus) | metrics | prometheus wrapper over [ydb-go-sdk-metrics](https://github.com/ydb-platform/ydb-go-sdk-metrics) | [ydbPrometheus.WithTraces](https://github.com/ydb-platform/ydb-go-sdk-prometheus/blob/master/internal/cmd/bench/main.go#L56)
81+
[ydb-go-sdk-opentracing](https://github.com/ydb-platform/ydb-go-sdk-opentracing) | tracing | opentracing plugin for trace internal ydb-go-sdk calls | [ydbOpentracing.WithTraces](https://github.com/ydb-platform/ydb-go-sdk-opentracing/blob/master/internal/cmd/bench/main.go#L86)
82+
83+
## Environment variables <a name="environ"></a>
84+
85+
`ydb-go-sdk` supports next environment variables which redefines default behavior of driver
86+
87+
Name | Type | Default | Description
88+
--- | --- | --- | ---
89+
`YDB_SSL_ROOT_CERTIFICATES_FILE` | `string` | | path to certificates file
90+
`YDB_LOG_SEVERITY_LEVEL` | `string` | `quiet` | severity logging level of internal driver logger. Supported: `trace`, `debug`, `info`, `warn`, `error`, `fatal`, `quiet`
91+
`YDB_LOG_NO_COLOR` | `bool` | `false` | set any non empty value to disable colouring logs with internal driver logger
92+
`GRPC_GO_LOG_VERBOSITY_LEVEL` | `integer` | | set to `99` to see grpc logs
93+
`GRPC_GO_LOG_SEVERITY_LEVEL` | `string` | | set to `info` to see grpc logs
1594
16-
See also [CREDENTIALS.md](CREDENTIALS.md) about supported YDB credentials.
1795
18-
See [DEBUG.md](DEBUG.md) about supported debug tooling over `ydb-go-sdk`.
1996
20-
See [ENVIRON.md](ENVIRON.md) about supported environment variables of `ydb-go-sdk`.

connection.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ func (c *connection) Scripting() scripting.Client {
223223
return c.scripting
224224
}
225225

226-
// New connects to name and return name runtime holder
226+
// New connects to database and return driver runtime holder
227227
func New(ctx context.Context, opts ...Option) (_ Connection, err error) {
228228
c := &connection{
229229
opts: opts,

example_table_test.go renamed to example_table_select_test.go

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@ import (
77
"github.com/ydb-platform/ydb-go-sdk/v3"
88
"github.com/ydb-platform/ydb-go-sdk/v3/table"
99
"github.com/ydb-platform/ydb-go-sdk/v3/table/result/named"
10-
"github.com/ydb-platform/ydb-go-sdk/v3/table/types"
1110
)
1211

13-
// nolint: govet
14-
func Example_TableUsage() {
12+
func Example_tableSelect() {
1513
ctx := context.Background()
1614
db, err := ydb.New(ctx,
1715
ydb.WithConnectionString("grpcs://localhost:2135/?database=/local"),
@@ -24,23 +22,14 @@ func Example_TableUsage() {
2422
_ = db.Close(ctx)
2523
}()
2624
var (
27-
txControl = table.TxControl(
28-
table.BeginTx(table.WithSerializableReadWrite()), table.CommitTx(),
29-
) // for managing transaction control during Execute
30-
query = `
31-
DECLARE $myStr AS Utf8;
32-
SELECT 42 as id, $myStr as myStr;
33-
`
34-
queryParams = table.NewQueryParameters(
35-
table.ValueParam("$myStr", types.UTF8Value("test")),
36-
) // ydb typed params for query
37-
id int32 // required value
38-
myStr *string // optional value
25+
query = `SELECT 42 as id, "my string" as myStr`
26+
id int32 // required value
27+
myStr string // optional value
3928
)
4029
err = db.Table().Do( // Do retry operation on errors with best effort
4130
ctx, // context manage exiting from Do
4231
func(ctx context.Context, s table.Session) (err error) { // retry operation
43-
_, res, err := s.Execute(ctx, txControl, query, queryParams)
32+
_, res, err := s.Execute(ctx, table.DefaultTxControl(), query, nil)
4433
if err != nil {
4534
return err // for driver retry
4635
}
@@ -53,12 +42,12 @@ func Example_TableUsage() {
5342
for res.NextRow() { // iterate over rows
5443
err = res.ScanNamed(
5544
named.Required("id", &id),
56-
named.Optional("myStr", &myStr),
45+
named.OptionalWithDefault("myStr", &myStr),
5746
)
5847
if err != nil {
5948
return err
6049
}
61-
log.Printf("id=%v, myStr=%v\n", id, *myStr)
50+
log.Printf("id=%v, myStr='%s'\n", id, myStr)
6251
}
6352
return res.Err() // for driver retry if not nil
6453
},

internal/table/session.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,10 @@ func (s *session) Execute(
625625
q := new(dataQuery)
626626
q.initFromText(query)
627627

628+
if params == nil {
629+
params = table.NewQueryParameters()
630+
}
631+
628632
onDone := trace.TableOnSessionQueryExecute(s.config.Trace(), &ctx, s, q, params)
629633
defer func() {
630634
onDone(txr, true, r, err)

table/table.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,14 @@ func TxControl(opts ...TxControlOption) *TransactionControl {
279279
return c
280280
}
281281

282+
// DefaultTxControl returns default transaction control with serializable read-write isolation mode and auto-commit
283+
func DefaultTxControl() *TransactionControl {
284+
return TxControl(
285+
BeginTx(WithSerializableReadWrite()),
286+
CommitTx(),
287+
)
288+
}
289+
282290
// QueryParameters
283291

284292
type (

ydb.go

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)