Skip to content

Commit 8c87a99

Browse files
committed
Fixes after review
1 parent 39c9f7e commit 8c87a99

File tree

2 files changed

+105
-56
lines changed
  • ydb/docs

2 files changed

+105
-56
lines changed

ydb/docs/en/core/dev/example-app/python/index.md

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,38 @@ App code snippet for driver initialization:
6161

6262
{% endlist %}
6363

64+
App code snippet for session pool initialization:
65+
66+
- Synchronous
67+
68+
```python
69+
with ydb.QuerySessionPool(driver) as pool:
70+
pass # operations with pool here
71+
```
72+
73+
- Asynchronous
74+
75+
```python
76+
async with ydb.aio.QuerySessionPoolAsync(driver) as pool:
77+
pass # operations with pool here
78+
```
79+
80+
{% endlist %}
81+
6482
## Executing queries
6583

66-
The {{ ydb-short-name }} Python SDK provides two primary methods for executing queries, each with different properties and use cases:
84+
{{ ydb-short-name }} Python SDK supports queries described by YQL syntax.
85+
There are two primary methods for executing queries, each with different properties and use cases:
6786

6887
* `pool.execute_with_retries`:
6988
* Buffers the entire result set in client memory.
7089
* Automatically retries execution in case of retriable issues.
7190
* Does not allow specifying a transaction execution mode.
7291
* Recommended for one-off queries that are expected to produce small result sets.
73-
92+
7493
* `tx.execute`:
7594
* Returns an iterator over the query results, allowing processing of results that may not fit into client memory.
76-
* Retries must be handled manually.
95+
* Retries must be handled manually via `pool.retry_operation_sync`.
7796
* Allows specifying a transaction execution mode.
7897
* Recommended for scenarios where `pool.execute_with_retries` is insufficient.
7998

@@ -177,7 +196,6 @@ To execute `CREATE TABLE` queries, use the `pool.execute_with_retries()` method:
177196

178197
{% endlist %}
179198

180-
181199
{% include [steps/03_write_queries.md](../_includes/steps/03_write_queries.md) %}
182200

183201
Code snippet for data insert/update:
@@ -274,7 +292,7 @@ To execute YQL queries, the `pool.execute_with_retries()` method is often suffic
274292

275293
{% endlist %}
276294

277-
As the result of executing the query, a `result_set` is returned, iterating on which the text is output to the console:
295+
As the result of executing the query, a list of `result_set` is returned, iterating on which the text is output to the console:
278296

279297
```bash
280298
> SelectSimple:
@@ -285,9 +303,9 @@ series, Id: 1, title: IT Crowd, Release date: 2006-02-03
285303

286304
For parameterized query execution, `pool.execute_with_retries()` and `tx.execute()` behave similarly. To execute parameterized queries, you need to pass a dictionary with parameters to one of these functions, where each key is the parameter name, and the value can be one of the following:
287305

288-
1. A value of a basic Python type
289-
2. A tuple containing the value and its type
290-
3. A special type, `ydb.TypedValue(value=value, value_type=value_type)`
306+
1. A value of a basic Python type
307+
2. A tuple containing the value and its type
308+
3. A special type, `ydb.TypedValue(value=value, value_type=value_type)`
291309

292310
If you specify a value without an explicit type, the conversion takes place according to the following rules:
293311

@@ -303,7 +321,7 @@ If you specify a value without an explicit type, the conversion takes place acco
303321

304322
{% note warning %}
305323

306-
Automatic conversion of lists and dictionaries is possible only if the structures are homogeneous. The type of nested values will be determined recursively according to the rules explained above.
324+
Automatic conversion of lists and dictionaries is possible only if the structures are homogeneous. The type of nested values will be determined recursively according to the rules explained above. In case of using heterogeneous structures, requests will raise `TypeError`.
307325

308326
{% endnote %}
309327

@@ -394,7 +412,7 @@ Available transaction modes:
394412

395413
For more information about transaction modes, see [{#T}](../../../concepts/transactions.md#modes).
396414

397-
The result of executing `tx.execute()` is an iterator. This iterator allows you to read result rows without loading the entire result set into memory. However, the iterator must be read to the end after each request to correctly maintain the transaction state on the {{ ydb-short-name }} server side. For convenience, the result of the `tx.execute()` function can be used as a context manager that automatically iterates to the end upon exit.
415+
The result of executing `tx.execute()` is an iterator. This iterator allows you to read result rows without loading the entire result set into memory. However, the iterator must be read to the end after each request to correctly maintain the transaction state on the {{ ydb-short-name }} server side. If this is not done, write queries could not be applied on the {{ ydb-short-name }} server side. For convenience, the result of the `tx.execute()` function can be used as a context manager that automatically iterates to the end upon exit.
398416

399417
{% list tabs %}
400418

@@ -414,7 +432,7 @@ The result of executing `tx.execute()` is an iterator. This iterator allows you
414432

415433
{% endlist %}
416434

417-
The code snippet below demonstrates the explicit use of `transaction().begin()` and `tx.commit()` with the transaction mode set to `ydb.QuerySerializableReadWrite()`:
435+
The code snippet below demonstrates the explicit use of `transaction().begin()` and `tx.commit()`:
418436

419437
{% list tabs %}
420438

@@ -434,7 +452,7 @@ The code snippet below demonstrates the explicit use of `transaction().begin()`
434452
"""
435453

436454
# Get newly created transaction id
437-
tx = session.transaction(ydb.QuerySerializableReadWrite()).begin()
455+
tx = session.transaction().begin()
438456

439457
# Execute data query.
440458
# Transaction control settings continues active transaction (tx)
@@ -474,7 +492,7 @@ The code snippet below demonstrates the explicit use of `transaction().begin()`
474492
"""
475493

476494
# Get newly created transaction id
477-
tx = await session.transaction(ydb.QuerySerializableReadWrite()).begin()
495+
tx = await session.transaction().begin()
478496

479497
# Execute data query.
480498
# Transaction control settings continues active transaction (tx)
@@ -515,7 +533,7 @@ Example of a `SELECT` with unlimited data and implicit transaction control:
515533
def callee(session: ydb.QuerySessionSync):
516534
query = """SELECT * from episodes;"""
517535

518-
with session.transaction().execute(
536+
with session.transaction(ydb.QuerySnapshotReadOnly()).execute(
519537
query,
520538
commit_tx=True,
521539
) as result_sets:
@@ -534,7 +552,7 @@ Example of a `SELECT` with unlimited data and implicit transaction control:
534552
async def callee(session: ydb.aio.QuerySessionAsync):
535553
query = """SELECT * from episodes;"""
536554

537-
async with await session.transaction().execute(
555+
async with await session.transaction(ydb.QuerySnapshotReadOnly()).execute(
538556
query,
539557
commit_tx=True,
540558
) as result_sets:

0 commit comments

Comments
 (0)