Skip to content

Commit e47e223

Browse files
committed
Update examples
1 parent bfd7361 commit e47e223

File tree

3 files changed

+21
-29
lines changed

3 files changed

+21
-29
lines changed

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
}
1010
],
1111
"require": {
12-
"php": ">=7.3",
12+
"php": ">=7.2",
1313
"ext-bcmath": "*",
1414
"ext-curl": "*",
1515
"ext-grpc": "*",
@@ -20,7 +20,8 @@
2020
"psr/log": "^1|^2|^3"
2121
},
2222
"require-dev": {
23-
"phpunit/phpunit": ">= 6.0, <10.0"
23+
"phpunit/phpunit": ">= 6.0, <10.0",
24+
"overtrue/phplint": "3.*"
2425
},
2526
"autoload": {
2627
"psr-4": {

examples/app/Commands/BasicExampleCommand.php

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -234,17 +234,15 @@ protected function describeTable($table)
234234

235235
protected function fillTablesWithData()
236236
{
237-
$this->ydb->table()->retrySession(function (Session $session) {
237+
$this->ydb->table()->retryTransaction(function (Session $session) {
238238

239239
$prepared_query = $session->prepare($this->getFillDataQuery());
240240

241-
$session->transaction(function () use ($prepared_query) {
242-
$prepared_query->execute([
243-
'seriesData' => $this->getSeriesData(),
244-
'seasonsData' => $this->getSeasonsData(),
245-
'episodesData' => $this->getEpisodesData(),
246-
]);
247-
});
241+
$prepared_query->execute([
242+
'seriesData' => $this->getSeriesData(),
243+
'seasonsData' => $this->getSeasonsData(),
244+
'episodesData' => $this->getEpisodesData(),
245+
]);
248246

249247
});
250248

@@ -253,7 +251,7 @@ protected function fillTablesWithData()
253251

254252
protected function selectSimple()
255253
{
256-
$session = $this->ydb->table()->session(function (Session $session){
254+
$result = $this->ydb->table()->retryTransaction(function (Session $session) {
257255

258256
$result = $session->transaction(function (Session $session) {
259257
return $session->query('
@@ -265,20 +263,17 @@ protected function selectSimple()
265263
FROM series
266264
WHERE series_id = 1;');
267265
});
268-
$this->print($result->rows());
269266
});
270267

268+
$this->print($result->rows());
271269
}
272270

273271
protected function upsertSimple()
274272
{
275-
$this->ydb->table()->retrySession(function (Session $session) {
276-
277-
$session->transaction(function (Session $session) {
278-
return $session->query('
273+
$this->ydb->table()->transaction(function (Session $session) {
274+
return $session->query('
279275
UPSERT INTO episodes (series_id, season_id, episode_id, title)
280276
VALUES (2, 6, 1, "TBD");');
281-
});
282277
});
283278

284279
$this->print('Finished.');
@@ -312,7 +307,7 @@ protected function bulkUpsert()
312307
*/
313308
protected function selectPrepared($series_id, $season_id, $episode_id)
314309
{
315-
$this->ydb->table()->retrySession(function (Session $session) use ($series_id, $season_id, $episode_id) {
310+
$this->ydb->table()->retryTransaction(function (Session $session) use ($series_id, $season_id, $episode_id) {
316311

317312
$prepared_query = $session->prepare('
318313
DECLARE $series_id AS Uint64;
@@ -326,13 +321,11 @@ protected function selectPrepared($series_id, $season_id, $episode_id)
326321
FROM episodes
327322
WHERE series_id = $series_id AND season_id = $season_id AND episode_id = $episode_id;');
328323

329-
$result = $session->transaction(function (Session $session) use ($prepared_query, $series_id, $season_id, $episode_id) {
330-
return $prepared_query->execute(compact(
331-
'series_id',
332-
'season_id',
333-
'episode_id'
334-
));
335-
});
324+
$result = $prepared_query->execute(compact(
325+
'series_id',
326+
'season_id',
327+
'episode_id'
328+
));
336329

337330
$this->print($result->rows());
338331
});
@@ -345,7 +338,7 @@ protected function selectPrepared($series_id, $season_id, $episode_id)
345338
*/
346339
protected function explicitTcl($series_id, $season_id, $episode_id)
347340
{
348-
$this->ydb->table()->retrySession(function (Session $session) use ($series_id, $season_id, $episode_id) {
341+
$this->ydb->table()->transaction(function (Session $session) use ($series_id, $season_id, $episode_id) {
349342

350343
$prepared_query = $session->prepare('
351344
DECLARE $today AS Uint64;
@@ -357,7 +350,6 @@ protected function explicitTcl($series_id, $season_id, $episode_id)
357350
SET air_date = $today
358351
WHERE series_id = $series_id AND season_id = $season_id AND episode_id = $episode_id;');
359352

360-
$session->beginTransaction();
361353

362354
$today = strtotime('today');
363355

@@ -368,7 +360,6 @@ protected function explicitTcl($series_id, $season_id, $episode_id)
368360
'today'
369361
));
370362

371-
$session->commitTransaction();
372363
});
373364

374365
$this->print('Finished.');

examples/app/Commands/CreateTableCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
4949

5050
$ydb = $this->appService->initYdb();
5151

52-
$ydb->table()->retrySession(function (Session $session){
52+
$ydb->table()->retrySession(function (Session $session) use ($output, $columns, $table_name) {
5353

5454
$result = $session->createTable($table_name, $columns, 'id');
5555

0 commit comments

Comments
 (0)