You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
4.[Retry helpers for `YDB``database/sql` driver](#retry)
15
-
*[Over `sql.Conn` object](#retry-conn)
16
-
*[Over `sql.Tx`](#retry-tx)
17
-
5.[Query args types](#arg-types)
18
-
6.[Get native driver from `*sql.DB`](#unwrap)
16
+
4.[Changing the transaction control mode](#tx-control)
17
+
5.[Retry helpers for `YDB``database/sql` driver](#retry)
18
+
*[Retries over `sql.Conn` object](#retry-conn)
19
+
*[Retries over `sql.Tx`](#retry-tx)
20
+
6.[Specifying query parameters](#arg-types)
21
+
7.[Accessing the native driver from `*sql.DB`](#unwrap)
19
22
20
23
## Initialization of `database/sql` driver <aname="init"></a>
21
24
@@ -42,7 +45,8 @@ func main() {
42
45
db:= sql.OpenDB(connector)
43
46
}
44
47
```
45
-
### Configure driver only with data source name (connection string) <aname="init-dsn"></a>
48
+
49
+
### Configure driver with data source name or connection string <aname="init-dsn"></a>
46
50
```go
47
51
import (
48
52
_ "github.com/ydb-platform/ydb-go-sdk/v3"
@@ -57,12 +61,12 @@ Data source name parameters:
57
61
* static credentials with authority part of URI, like `grpcs://root:password@localhost:2135/local`
58
62
*`query_mode=scripting` - you can redefine default [DML](https://en.wikipedia.org/wiki/Data_manipulation_language) query mode
59
63
60
-
## Execute queries <aname="queries"></a>
64
+
## Query execution <aname="queries"></a>
61
65
62
-
### On database object <aname="queries-db"></a>
66
+
### Queries on database object <aname="queries-db"></a>
63
67
```go
64
68
rows, err:= db.QueryContext(ctx,
65
-
"SELECT series_id, title, release_date FROM /full/path/of/table/series;"
69
+
"SELECT series_id, title, release_date FROM `/full/path/of/table/series`;"
66
70
)
67
71
if err != nil {
68
72
log.Fatal(err)
@@ -85,19 +89,23 @@ if err = rows.Err(); err != nil { // always check final rows err
85
89
}
86
90
```
87
91
88
-
### With transaction <aname="queries-tx"></a>
89
-
Supports only `default` transaction options which mapped to `YDB``SerializableReadWrite` transaction settings.
92
+
### Queries on transaction object <aname="queries-tx"></a>
93
+
Query execution on transaction object supports only `default` transaction options
94
+
which are mapped to `YDB``SerializableReadWrite` transaction settings.
95
+
96
+
`YDB`'s `OnlineReadOnly` and `StaleReadOnly` transaction settings are not compatible
97
+
with interactive transactions such as `database/sql`'s `*sql.Tx`.
98
+
That's why `ydb-go-sdk` implements read-only `sql.LevelSnapshot` with fake transaction
99
+
(temporary, until `YDB` starts to support true snapshot isolation mode).
90
100
91
-
`YDB`'s `OnlineReadOnly` and `StaleReadOnly` transaction settings are not compatible with interactive transactions such as `database/sql`'s `*sql.Tx`.
92
-
That's why `ydb-go-sdk` implements read-only `sql.LevelSnapshot` with fake transaction (temporary, while `YDB` main clusters are supports true snapshot isolation mode)
93
101
```go
94
102
tx, err:= db.BeginTx(ctx, sql.TxOptions{})
95
103
if err != nil {
96
104
log.Fatal(err)
97
105
}
98
106
defer tx.Rollback()
99
107
rows, err:= tx.QueryContext(ctx,
100
-
"SELECT series_id, title, release_date FROM /full/path/of/table/series;"
108
+
"SELECT series_id, title, release_date FROM `/full/path/of/table/series`;"
The `YDB` server API is currently requires to select a specific method by specific request type. For example, [DDL](https://en.wikipedia.org/wiki/Data_definition_language) must be called with `table.session.ExecuteSchemeQuery`, [DML](https://en.wikipedia.org/wiki/Data_manipulation_language) must be called with `table.session.Execute`, [DQL](https://en.wikipedia.org/wiki/Data_query_language) may be called with `table.session.Execute` or `table.session.StreamExecuteScanQuery` etc. `YDB` have a `scripting` service also, which provides different query types with single method, but not supports transactions.
135
+
Currently the `YDB` server APIs require the use of a proper GRPC service method depending on the specific request type.
136
+
In particular, [DDL](https://en.wikipedia.org/wiki/Data_definition_language) must be called through `table.session.ExecuteSchemeQuery`,
137
+
[DML](https://en.wikipedia.org/wiki/Data_manipulation_language) needs `table.session.Execute`, and
138
+
[DQL](https://en.wikipedia.org/wiki/Data_query_language) should be passed via `table.session.Execute` or `table.session.StreamExecuteScanQuery`.
139
+
`YDB` also has a so-called "scripting" service, which supports different query types within a single method,
140
+
but without support for transactions.
127
141
128
-
That's why needs to select query mode on client side currently.
142
+
Unfortunately, this leads to the need to choose the proper query mode on the application side.
129
143
130
-
`YDB` team have a roadmap goal to implements a single method for executing different query types.
144
+
`YDB` team has a roadmap goal to implement a single universal service method for executing
145
+
different query types and without the limitations of the "scripting" service method.
131
146
132
-
`database/sql` driver implementation for `YDB` supports next query modes:
147
+
`database/sql` driver implementation for `YDB` supports the following query modes:
133
148
*`ydb.DataQueryMode` - default query mode, for lookup [DQL](https://en.wikipedia.org/wiki/Data_query_language) queries and [DML](https://en.wikipedia.org/wiki/Data_manipulation_language) queries.
134
-
*`ydb.ExplainQueryMode` - for gettting plan and [AST](https://en.wikipedia.org/wiki/Abstract_syntax_tree) of some query
135
-
*`ydb.ScanQueryMode` - for strong[OLAP](https://en.wikipedia.org/wiki/Online_analytical_processing) scenarious, [DQL-only](https://en.wikipedia.org/wiki/Data_query_language) queries. Read more about scan queries in [ydb.tech](https://ydb.tech/en/docs/concepts/scan_query)
149
+
*`ydb.ExplainQueryMode` - for gettting plan and [AST](https://en.wikipedia.org/wiki/Abstract_syntax_tree) of the query
150
+
*`ydb.ScanQueryMode` - for heavy[OLAP](https://en.wikipedia.org/wiki/Online_analytical_processing)style scenarious, with[DQL-only](https://en.wikipedia.org/wiki/Data_query_language) queries. Read more about scan queries in [ydb.tech](https://ydb.tech/en/docs/concepts/scan_query)
136
151
*`ydb.SchemeQueryMode` - for [DDL](https://en.wikipedia.org/wiki/Data_definition_language) queries
137
-
*`ydb.ScriptingQueryMode` - for [DDL](https://en.wikipedia.org/wiki/Data_definition_language), [DML](https://en.wikipedia.org/wiki/Data_manipulation_language), [DQL](https://en.wikipedia.org/wiki/Data_query_language) queries (not a [TCL](https://en.wikipedia.org/wiki/SQL#Transaction_controls)). Be careful: queries executes longer than with other query modes and consumes bigger server-side resources
152
+
*`ydb.ScriptingQueryMode` - for [DDL](https://en.wikipedia.org/wiki/Data_definition_language), [DML](https://en.wikipedia.org/wiki/Data_manipulation_language), [DQL](https://en.wikipedia.org/wiki/Data_query_language) queries (not a [TCL](https://en.wikipedia.org/wiki/SQL#Transaction_controls)). Be careful: queries execute longer than with other query modes, and consume more server-side resources
0 commit comments