Skip to content

Commit 26e28ec

Browse files
committed
misc cleanup for readability
1 parent defb7da commit 26e28ec

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

spanner/composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
"require": {
3-
"google/cloud-spanner": "1.200",
4-
"google/gax": "dev-result-function as 1.40.0"
3+
"google/cloud-spanner": "1.200"
54
},
65
"autoload": {
76
"psr-4": {

spanner/src/create_database_with_proto_columns.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,17 @@ function create_database_with_proto_columns(
4343
string $instanceId,
4444
string $databaseId
4545
): void {
46+
// The result of running `protoc` with `--descriptor_set_out` on your proto file(s)
47+
$fileDescriptorSet = file_get_contents('data/user.pb');
48+
4649
$databaseAdminClient = new DatabaseAdminClient();
4750
$instance = $databaseAdminClient->instanceName($projectId, $instanceId);
4851

4952
$operation = $databaseAdminClient->createDatabase(
5053
new CreateDatabaseRequest([
5154
'parent' => $instance,
5255
'create_statement' => sprintf('CREATE DATABASE `%s`', $databaseId),
53-
'proto_descriptors' => file_get_contents('data/user.pb'),
56+
'proto_descriptors' => $fileDescriptorSet,
5457
'extra_statements' => [
5558
'CREATE PROTO BUNDLE (' .
5659
'testing.data.User,' .
@@ -69,8 +72,7 @@ function create_database_with_proto_columns(
6972
print('Waiting for operation to complete...' . PHP_EOL);
7073
$operation->pollUntilComplete();
7174

72-
printf('Created database %s on instance %s' . PHP_EOL,
73-
$databaseId, $instanceId);
75+
printf('Created database %s on instance %s' . PHP_EOL, $databaseId, $instanceId);
7476
}
7577
// [END spanner_create_database_with_proto_columns]
7678

spanner/src/insert_data_with_proto_columns.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ function insert_data_with_proto_columns(
4949
int $userId = 1,
5050
): void {
5151
$spanner = new SpannerClient();
52-
$instance = $spanner->instance($instanceId);
53-
$database = $instance->database($databaseId);
54-
$user = new User();
55-
$user->setName('Test User ' . $userId);
56-
$address = new User\Address();
57-
$address->setCity('San Francisco');
58-
$address->setState('CA');
59-
$user->setAddress($address);
52+
$database = $spanner->instance($instanceId)->database($databaseId);
53+
54+
$address = (new User\Address())
55+
->setCity('San Francisco')
56+
->setState('CA');
57+
$user = (new User())
58+
->setName('Test User ' . $userId)
59+
->setAddress($address);
6060

6161
$book1 = new Book(['title' => 'Book 1', 'author' => 'Author 1']);
6262
$book2 = new Book(['title' => 'Book 2', 'author' => 'Author 2']);

spanner/src/query_data_with_proto_columns.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,10 @@ function query_data_with_proto_columns(
4444
string $databaseId,
4545
int $userId = 1
4646
): void {
47+
// [START spanner_query_data_with_proto_columns]
4748
$spanner = new SpannerClient();
48-
$instance = $spanner->instance($instanceId);
49-
$database = $instance->database($databaseId);
49+
$database = $spanner->instance($instanceId)->database($databaseId);
5050

51-
// [START spanner_query_data_with_proto_columns]
5251
$userProto = (new User())
5352
->setName('Test User ' . $userId);
5453

@@ -71,7 +70,7 @@ function query_data_with_proto_columns(
7170
/** @var Proto<Book> $book */
7271
foreach ($row['Books'] ?? [] as $book) {
7372
// Print the raw row value
74-
printf('Book: %s' . PHP_EOL, $book->getValue());
73+
printf('Book: %s (%s)' . PHP_EOL, $book->getValue(), $book->getProtoTypeFqn());
7574
}
7675
}
7776
// [END spanner_query_data_with_proto_columns]

0 commit comments

Comments
 (0)