Skip to content

Commit 2ac9fca

Browse files
jmukstephenplusplus
authored andcommitted
spanner: hello.
0 parents  commit 2ac9fca

38 files changed

+17502
-0
lines changed

README.md

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
# @google-cloud/spanner ([Alpha][versioning])
2+
> Cloud Spanner Client Library for Node.js
3+
4+
*Looking for more Google APIs than just Cloud Spanner? You might want to check out [`google-cloud`][google-cloud].*
5+
6+
- [API Documentation][gcloud-spanner-docs]
7+
- [Official Documentation][cloud-spanner-docs]
8+
9+
10+
```sh
11+
$ npm install --save @google-cloud/spanner
12+
```
13+
```js
14+
var spanner = require('@google-cloud/spanner')({
15+
projectId: 'grape-spaceship-123',
16+
keyFilename: '/path/to/keyfile.json'
17+
});
18+
19+
var instance = spanner.instance('my-instance');
20+
var database = instance.database('my-database');
21+
22+
// Create a table.
23+
var schema =
24+
'CREATE TABLE Singers (' +
25+
' SingerId INT64 NOT NULL,' +
26+
' FirstName STRING(1024),' +
27+
' LastName STRING(1024),' +
28+
' SingerInfo BYTES(MAX),' +
29+
') PRIMARY KEY(SingerId)';
30+
31+
database.createTable(schema, function(err, table, operation) {
32+
if (err) {
33+
// Error handling omitted.
34+
}
35+
36+
operation
37+
.on('error', function(err) {})
38+
.on('complete', function() {
39+
// Table created successfully.
40+
});
41+
});
42+
43+
// Insert data into the table.
44+
var table = database.table('Singers');
45+
46+
table.insert({
47+
SingerId: 10,
48+
FirstName: 'Eddie',
49+
LastName: 'Wilson'
50+
}, function(err) {
51+
if (!err) {
52+
// Row inserted successfully.
53+
}
54+
});
55+
56+
// Run a query as a readable object stream.
57+
database.runStream('SELECT * FROM Singers')
58+
.on('error', function(err) {})
59+
.on('data', function(row) {
60+
// row.toJSON() = {
61+
// SingerId: 10,
62+
// FirstName: 'Eddie',
63+
// LastName: 'Wilson'
64+
// }
65+
}
66+
})
67+
.on('end', function() {
68+
// All results retrieved.
69+
});
70+
```
71+
72+
73+
## Authentication
74+
75+
It's incredibly easy to get authenticated and start using Google's APIs. You can set your credentials on a global basis as well as on a per-API basis. See each individual API section below to see how you can auth on a per-API-basis. This is useful if you want to use different accounts for different Google Cloud services.
76+
77+
### On Google Cloud Platform
78+
79+
If you are running this client on Google Cloud Platform, we handle authentication for you with no configuration. You just need to make sure that when you [set up the GCE instance][gce-how-to], you add the correct scopes for the APIs you want to access.
80+
81+
``` js
82+
var spanner = require('@google-cloud/spanner')();
83+
// ...you're good to go!
84+
```
85+
86+
### Elsewhere
87+
88+
If you are not running this client on Google Cloud Platform, you need a Google Developers service account. To create a service account:
89+
90+
1. Visit the [Google Developers Console][dev-console].
91+
2. Create a new project or click on an existing project.
92+
3. Navigate to **APIs & auth** > **APIs section** and turn on the following APIs (you may need to enable billing in order to use these services):
93+
* Cloud Spanner API
94+
4. Navigate to **APIs & auth** > **Credentials** and then:
95+
* If you want to use a new service account key, click on **Create credentials** and select **Service account key**. After the account key is created, you will be prompted to download the JSON key file that the library uses to authenticate your requests.
96+
* If you want to generate a new service account key for an existing service account, click on **Generate new JSON key** and download the JSON key file.
97+
98+
``` js
99+
var projectId = process.env.GCLOUD_PROJECT; // E.g. 'grape-spaceship-123'
100+
101+
var spanner = require('@google-cloud/spanner')({
102+
projectId: projectId,
103+
104+
// The path to your key file:
105+
keyFilename: '/path/to/keyfile.json'
106+
107+
// Or the contents of the key file:
108+
credentials: require('./path/to/keyfile.json')
109+
});
110+
111+
// ...you're good to go!
112+
```
113+
114+
115+
[versioning]: https://github.com/GoogleCloudPlatform/google-cloud-node#versioning
116+
[google-cloud]: https://github.com/GoogleCloudPlatform/google-cloud-node/
117+
[gce-how-to]: https://cloud.google.com/compute/docs/authentication#using
118+
[dev-console]: https://console.developers.google.com/project
119+
[gcloud-spanner-docs]: https://googlecloudplatform.github.io/google-cloud-node/#/docs/spanner
120+
[cloud-spanner-docs]: https://cloud.google.com/spanner

package.json

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"name": "@google-cloud/spanner",
3+
"version": "0.0.0",
4+
"author": "Google Inc.",
5+
"description": "Cloud Spanner Client Library for Node.js",
6+
"contributors": [
7+
{
8+
"name": "Dave Gramlich",
9+
"email": "callmehiphop@gmail.com"
10+
},
11+
{
12+
"name": "Stephen Sawchuk",
13+
"email": "sawchuk@gmail.com"
14+
}
15+
],
16+
"main": "./src/index.js",
17+
"files": [
18+
"src",
19+
"AUTHORS",
20+
"CONTRIBUTORS",
21+
"COPYING"
22+
],
23+
"repository": "googlecloudplatform/google-cloud-node",
24+
"keywords": [
25+
"google apis client",
26+
"google api client",
27+
"google apis",
28+
"google api",
29+
"google",
30+
"google cloud platform",
31+
"google cloud",
32+
"cloud",
33+
"spanner"
34+
],
35+
"dependencies": {
36+
"@google-cloud/common": "^0.12.0",
37+
"@google-cloud/common-grpc": "^0.1.4",
38+
"arrify": "^1.0.1",
39+
"checkpoint-stream": "^0.1.0",
40+
"events-intercept": "^2.0.0",
41+
"extend": "^3.0.0",
42+
"generic-pool": "^3.1.4",
43+
"google-gax": "^0.10.0",
44+
"google-proto-files": "^0.9.0",
45+
"is": "^3.1.0",
46+
"lodash.chunk": "^4.2.0",
47+
"lodash.snakecase": "^4.1.1",
48+
"merge-stream": "^1.0.1",
49+
"split-array-stream": "^1.0.0",
50+
"stream-events": "^1.0.1",
51+
"string-format-obj": "^1.1.0",
52+
"through2": "^2.0.3"
53+
},
54+
"devDependencies": {
55+
"async": "^2.0.1",
56+
"concat-stream": "^1.6.0",
57+
"methmeth": "^1.1.0",
58+
"mocha": "^3.0.1",
59+
"multiline": "^1.0.2",
60+
"proxyquire": "^1.7.11",
61+
"uuid": "^3.0.1"
62+
},
63+
"scripts": {
64+
"publish-module": "node ../../scripts/publish.js resource",
65+
"test": "mocha test/*.js",
66+
"system-test": "mocha system-test/*.js --no-timeouts --bail"
67+
},
68+
"license": "Apache-2.0",
69+
"engines": {
70+
"node": ">=4.0.0"
71+
}
72+
}

src/admin/database/index.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*!
2+
* Copyright 2016 Google Inc. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
'use strict';
17+
18+
module.exports.v1 = require('./v1');

0 commit comments

Comments
 (0)