From 81c0ceaadafecbc0f73e5e030deb67d69f96f9f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=BB=D1=8C=D1=8F?= <38153753+ilyakharev@users.noreply.github.com> Date: Wed, 12 Jul 2023 13:32:32 +0300 Subject: [PATCH 1/2] Update README.md --- README.md | 46 +++++++++++++++++----------------------------- 1 file changed, 17 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index 21d09123..4d433caa 100644 --- a/README.md +++ b/README.md @@ -419,7 +419,7 @@ The following algorithm that is the same for YDB-PHP-SDK applies: # Usage -You should initialize a session from the Table service to start querying. +You should initialize a session from the Table service to start querying with retry. ```php table(); -// obtaining a session -$session = $table->session(); - -// making a query -$result = $session->query('select * from `users` limit 10;'); +$result = $table->retrySession(function(Session $session){ + // making a query + return $session->query('select * from `users` limit 10;'); +}, true); $users_count = $result->rowCount(); $users = $result->rows(); @@ -448,18 +447,6 @@ $columns = $result->columns(); ``` -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. - -```php -table(); - -// making a query -$result = $table->query('select * from `users` limit 10;'); - -``` - As soon as your script is finished, the session will be destroyed. ## Customizing queries @@ -469,18 +456,19 @@ Normally, a regular query through the `query()` method is sufficient, but in exc ```php session(); - -// creating a new query builder instance -$query = $session->newQuery('select * from `users` limit 10;'); - -// a setting to keep in cache -$query->keepInCache(); +$result = $table->retrySession(function(Session $session){ -// a setting to begin a transaction with the given mode -$query->beginTx('stale'); - -$result = $query->execute(); + // creating a new query builder instance + $query = $session->newQuery('select * from `users` limit 10;'); + + // a setting to keep in cache + $query->keepInCache(); + + // a setting to begin a transaction with the given mode + $query->beginTx('stale'); + + return $query->execute(); +}, true); ``` Methods of the query builder: From 9eaf38cf4768a8f2b2437b4f591def11ae936309 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=98=D0=BB=D1=8C=D1=8F?= <38153753+ilyakharev@users.noreply.github.com> Date: Wed, 12 Jul 2023 13:48:15 +0300 Subject: [PATCH 2/2] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4d433caa..10a00c3e 100644 --- a/README.md +++ b/README.md @@ -435,7 +435,7 @@ $ydb = new Ydb($config); // obtaining the Table service $table = $ydb->table(); -$result = $table->retrySession(function(Session $session){ +$result = $table->retryTransaction(function(Session $session){ // making a query return $session->query('select * from `users` limit 10;'); }, true); @@ -456,7 +456,7 @@ Normally, a regular query through the `query()` method is sufficient, but in exc ```php retrySession(function(Session $session){ +$result = $table->retryTransaction(function(Session $session){ // creating a new query builder instance $query = $session->newQuery('select * from `users` limit 10;');