Skip to content

Commit a40f399

Browse files
committed
SQL docs
1 parent 0ca63f0 commit a40f399

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

SQL.md

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Behind the scene, `database/sql` APIs are implemented using the native interface
1313
3. [Query execution](#queries)
1414
* [Queries on database object](#queries-db)
1515
* [Queries on transaction object](#queries-tx)
16+
* [Supported isolation levels](#isolation)
1617
4. [Query modes (DDL, DML, DQL, etc.)](#query-modes)
1718
5. [Retry helpers for `YDB` `database/sql` driver](#retry)
1819
* [Over `sql.Conn` object](#retry-conn)
@@ -112,16 +113,28 @@ if err = rows.Err(); err != nil { // always check final rows err
112113
```
113114

114115
### Queries on transaction object <a name="queries-tx"></a>
115-
Query execution on transaction object supports only `default` transaction options
116-
which are mapped to `YDB` `SerializableReadWrite` transaction settings.
117116

118-
`YDB`'s `OnlineReadOnly` and `StaleReadOnly` transaction settings are not compatible
119-
with interactive transactions such as `database/sql`'s `*sql.Tx`.
120-
That's why `ydb-go-sdk` implements read-only `sql.LevelSnapshot` with fake transaction
121-
(temporary, until `YDB` starts to support true snapshot isolation mode).
117+
- read-write (mapped to `SerializableReadWrite` transaction control)
118+
```go
119+
rw := sql.TxOption{
120+
ReadOnly: false,
121+
Isolation: sql.LevelDefault,
122+
}
123+
```
124+
- read-only (mapped to `OnlineReadOnly` transaction settings on each request, will be mapped to true `SnapshotReadOnly` soon)
125+
```go
126+
ro := sql.TxOption{
127+
ReadOnly: true,
128+
Isolation: sql.LevelSnapshot,
129+
}
130+
```
122131

132+
Example of works with transactions:
123133
```go
124-
tx, err := db.BeginTx(ctx, sql.TxOptions{})
134+
tx, err := db.BeginTx(ctx, sql.TxOption{
135+
ReadOnly: true,
136+
Isolation: sql.LevelSnapshot,
137+
})
125138
if err != nil {
126139
log.Fatal(err)
127140
}

SQL_MIGRATION_v2_v3.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,10 @@
33
> Article contains some cases for migrate from `github.com/yandex-cloud/ydb-go-sdk/v2/ydbsql` to `github.com/ydb-platform/ydb-go-sdk/v3`
44
55
> Note: the article is being updated.
6+
7+
## Read-only isolation levels
8+
9+
In `ydb-go-sdk/v2/ydbsql` was allowed `sql.LevelReadCommitted` and `sql.LevelReadUncommitted` isolation levels for read-only interactive transactions. It implements with fake transaction with true `OnlineReadOnly` transaction control on each query inside transaction.
10+
11+
`ydb-go-sdk/v3` allowed only `sql.LevelSnapshot` for read-only interactive transactions. Currently, snapshot isolation implements over fake transaction with true `OnlineReadOnly` transaction control.
12+
YDB implements snapshot isolation, but this feature is not deployed on YDB clusters now. After full deploying on each YDB cluster fake transaction will be replaced to true read-only interactive transaction with snapshot isolation level.

0 commit comments

Comments
 (0)