Skip to content

Commit 30e1c58

Browse files
authored
Add spanner samples and quickstart (GoogleCloudPlatform#372)
1 parent b28c94d commit 30e1c58

22 files changed

+3782
-0
lines changed

spanner/README.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
Google Cloud Spanner PHP Samples
2+
================================
3+
4+
This directory contains samples for Google Cloud Spanner.
5+
[Google Cloud Spanner][spanner] is a highly scalable, transactional, managed,
6+
[NewSQL][newsql] database service. Cloud Spanner solves the need for a
7+
horizontally-scaling database with consistent global transactions and SQL
8+
semantics.
9+
10+
[spanner]: https://cloud.google.com/spanner/docs
11+
[newsql]: https://en.wikipedia.org/wiki/NewSQL
12+
13+
## Setup
14+
15+
### Authentication
16+
17+
Authentication is typically done through [Application Default Credentials][adc]
18+
which means you do not have to change the code to authenticate as long as
19+
your environment has credentials. You have a few options for setting up
20+
authentication:
21+
22+
1. When running locally, use the [Google Cloud SDK][google-cloud-sdk]
23+
24+
gcloud auth application-default login
25+
26+
1. When running on App Engine or Compute Engine, credentials are already
27+
set-up. However, you may need to configure your Compute Engine instance
28+
with [additional scopes][additional_scopes].
29+
30+
1. You can create a [Service Account key file][service_account_key_file]. This file can be used to
31+
authenticate to Google Cloud Platform services from any environment. To use
32+
the file, set the ``GOOGLE_APPLICATION_CREDENTIALS`` environment variable to
33+
the path to the key file, for example:
34+
35+
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/service_account.json
36+
37+
[adc]: https://cloud.google.com/docs/authentication#getting_credentials_for_server-centric_flow
38+
[additional_scopes]: https://cloud.google.com/compute/docs/authentication#using
39+
[service_account_key_file]: https://developers.google.com/identity/protocols/OAuth2ServiceAccount#creatinganaccount
40+
41+
## Install Dependencies
42+
43+
1. [Enable the Cloud Spanner API](https://console.cloud.google.com/flows/enableapi?apiid=spanner.googleapis.com).
44+
45+
1. **Install dependencies** via [Composer](http://getcomposer.org/doc/00-intro.md).
46+
Run `php composer.phar install` (if composer is installed locally) or `composer install`
47+
(if composer is installed globally).
48+
49+
1. Create a service account at the
50+
[Service account section in the Cloud Console](https://console.cloud.google.com/iam-admin/serviceaccounts/)
51+
52+
1. Download the json key file of the service account.
53+
54+
1. Set `GOOGLE_APPLICATION_CREDENTIALS` environment variable pointing to that file.
55+
56+
## Samples
57+
58+
To run the Spanner Samples:
59+
60+
$ php spanner.php
61+
62+
Cloud Spanner
63+
64+
Usage:
65+
command [options] [arguments]
66+
67+
Options:
68+
-h, --help Display this help message
69+
-q, --quiet Do not output any message
70+
-V, --version Display this application version
71+
--ansi Force ANSI output
72+
--no-ansi Disable ANSI output
73+
-n, --no-interaction Do not ask any interactive question
74+
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
75+
76+
Available commands:
77+
add-column Adds a new column to the Albums table in the example database.
78+
create-database Creates a database and tables for sample data.
79+
create-index Adds a simple index to the example database.
80+
create-storing-index Adds an storing index to the example database.
81+
help Displays help for a command
82+
insert-data Inserts sample data into the given database.
83+
list Lists commands
84+
query-data Queries sample data from the database using SQL.
85+
query-data-with-index Queries sample data from the database using SQL and an index.
86+
query-data-with-new-column Queries sample data from the database using SQL.
87+
read-data Reads sample data from the database.
88+
read-data-with-index Reads sample data from the database using an index.
89+
read-data-with-storing-index Reads sample data from the database using an index with a storing clause.
90+
read-only-transaction Reads data inside of a read-only transaction.
91+
read-write-transaction Performs a read-write transaction to update two sample records in the database.
92+
update-data Updates sample data in the database.
93+
94+
95+
96+
## The client library
97+
98+
This sample uses the [Google Cloud Client Library for PHP][google-cloud-php].
99+
You can read the documentation for more details on API usage and use GitHub
100+
to [browse the source][google-cloud-php-source] and [report issues][google-cloud-php-issues].
101+
102+
[google-cloud-php]: https://googlecloudplatform.github.io/google-cloud-php
103+
[google-cloud-php-source]: https://github.com/GoogleCloudPlatform/google-cloud-php
104+
[google-cloud-php-issues]: https://github.com/GoogleCloudPlatform/google-cloud-php/issues
105+
[google-cloud-sdk]: https://cloud.google.com/sdk/

spanner/composer.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"require": {
3+
"google/cloud-spanner": "^0.1.1",
4+
"symfony/console": "^3.2"
5+
},
6+
"require-dev": {
7+
"phpunit/phpunit": "^4"
8+
},
9+
"autoload": {
10+
"files": [
11+
"src/add_column.php",
12+
"src/insert_data.php",
13+
"src/read_data.php",
14+
"src/read_write_transaction.php",
15+
"src/create_database.php",
16+
"src/query_data.php",
17+
"src/read_data_with_index.php",
18+
"src/update_data.php",
19+
"src/create_index.php",
20+
"src/query_data_with_index.php",
21+
"src/read_data_with_storing_index.php",
22+
"src/create_storing_index.php",
23+
"src/query_data_with_new_column.php",
24+
"src/read_only_transaction.php"
25+
]
26+
}
27+
}

0 commit comments

Comments
 (0)