Skip to content

Commit 6fc8d9a

Browse files
authored
Merge pull request #91 from ydb-platform/update-readme
Update README.md
2 parents 94a9844 + dc4d7f5 commit 6fc8d9a

File tree

1 file changed

+17
-29
lines changed

1 file changed

+17
-29
lines changed

README.md

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ The following algorithm that is the same for YDB-PHP-SDK applies:
419419

420420
# Usage
421421

422-
You should initialize a session from the Table service to start querying.
422+
You should initialize a session from the Table service to start querying with retry.
423423

424424
```php
425425
<?php
@@ -435,11 +435,10 @@ $ydb = new Ydb($config);
435435
// obtaining the Table service
436436
$table = $ydb->table();
437437

438-
// obtaining a session
439-
$session = $table->session();
440-
441-
// making a query
442-
$result = $session->query('select * from `users` limit 10;');
438+
$result = $table->retryTransaction(function(Session $session){
439+
// making a query
440+
return $session->query('select * from `users` limit 10;');
441+
}, true);
443442

444443
$users_count = $result->rowCount();
445444
$users = $result->rows();
@@ -448,18 +447,6 @@ $columns = $result->columns();
448447

449448
```
450449

451-
Also, you may call the `query()` method directly on the Table service. In this case a session will be created behind the scenes, and it will proxy your query to the session.
452-
453-
```php
454-
<?php
455-
456-
$table = $ydb->table();
457-
458-
// making a query
459-
$result = $table->query('select * from `users` limit 10;');
460-
461-
```
462-
463450
As soon as your script is finished, the session will be destroyed.
464451

465452
## Customizing queries
@@ -469,18 +456,19 @@ Normally, a regular query through the `query()` method is sufficient, but in exc
469456
```php
470457
<?php
471458

472-
$session = $table->session();
473-
474-
// creating a new query builder instance
475-
$query = $session->newQuery('select * from `users` limit 10;');
476-
477-
// a setting to keep in cache
478-
$query->keepInCache();
459+
$result = $table->retryTransaction(function(Session $session){
479460

480-
// a setting to begin a transaction with the given mode
481-
$query->beginTx('stale');
482-
483-
$result = $query->execute();
461+
// creating a new query builder instance
462+
$query = $session->newQuery('select * from `users` limit 10;');
463+
464+
// a setting to keep in cache
465+
$query->keepInCache();
466+
467+
// a setting to begin a transaction with the given mode
468+
$query->beginTx('stale');
469+
470+
return $query->execute();
471+
}, true);
484472
```
485473

486474
Methods of the query builder:

0 commit comments

Comments
 (0)