Skip to content

Commit 8875f2c

Browse files
authored
Merge branch 'googleapis:main' into main
2 parents c0c935e + 090e2e8 commit 8875f2c

File tree

14 files changed

+1713
-317
lines changed

14 files changed

+1713
-317
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ system-test/*key.json
1212
.DS_Store
1313
package-lock.json
1414
__pycache__
15+
.vscode

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44

55
[1]: https://www.npmjs.com/package/nodejs-spanner?activeTab=versions
66

7+
## [7.6.0](https://github.com/googleapis/nodejs-spanner/compare/v7.5.0...v7.6.0) (2024-03-26)
8+
9+
10+
### Features
11+
12+
* Add instance partition support to spanner instance proto ([#2001](https://github.com/googleapis/nodejs-spanner/issues/2001)) ([4381047](https://github.com/googleapis/nodejs-spanner/commit/43810478e81d3a234e7fa94af90fd49ca379dd98))
13+
* Managed Autoscaler ([#2015](https://github.com/googleapis/nodejs-spanner/issues/2015)) ([547ca1b](https://github.com/googleapis/nodejs-spanner/commit/547ca1b0da8c5c5e28f85fbd4ea16af21e20c980))
14+
* **spanner:** Add a sample for max commit delays ([#1993](https://github.com/googleapis/nodejs-spanner/issues/1993)) ([91c7204](https://github.com/googleapis/nodejs-spanner/commit/91c7204e2c8f62e229d7a2b2a0ff059d421dd984))
15+
* **spanner:** Add support for float32 ([#2020](https://github.com/googleapis/nodejs-spanner/issues/2020)) ([99e2c1d](https://github.com/googleapis/nodejs-spanner/commit/99e2c1d4791a5ca86fdccb3f600aa4592efe0a45))
16+
717
## [7.5.0](https://github.com/googleapis/nodejs-spanner/compare/v7.4.0...v7.5.0) (2024-03-04)
818

919

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ Samples are in the [`samples/`](https://github.com/googleapis/nodejs-spanner/tre
139139
| Json-update-data | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/json-update-data.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/json-update-data.js,samples/README.md) |
140140
| Lists all databases on the selected instance | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/list-databases.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/list-databases.js,samples/README.md) |
141141
| Lists all the available instance configs for the selected project. | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/list-instance-configs.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/list-instance-configs.js,samples/README.md) |
142+
| Executes request with max commit delay | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/max-commit-delay.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/max-commit-delay.js,samples/README.md) |
142143
| Numeric-add-column | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/numeric-add-column.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/numeric-add-column.js,samples/README.md) |
143144
| Numeric-query-parameter | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/numeric-query-parameter.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/numeric-query-parameter.js,samples/README.md) |
144145
| Numeric-update-data | [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/numeric-update-data.js) | [![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/numeric-update-data.js,samples/README.md) |

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@google-cloud/spanner",
33
"description": "Cloud Spanner Client Library for Node.js",
4-
"version": "7.5.0",
4+
"version": "7.6.0",
55
"license": "Apache-2.0",
66
"author": "Google Inc.",
77
"engines": {
@@ -30,6 +30,7 @@
3030
"docs": "jsdoc -c .jsdoc.js",
3131
"predocs": "npm run compile",
3232
"lint": "gts check",
33+
"samples-test-with-archived": "cd samples/ && npm link ../ && npm test-with-archived && cd ../",
3334
"samples-test": "cd samples/ && npm link ../ && npm test && cd ../",
3435
"system-test": "mocha build/system-test --timeout 1600000",
3536
"cleanup": "mocha scripts/cleanup.js --timeout 30000",

samples/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ and automatic, synchronous replication for high availability.
6464
* [Json-update-data](#json-update-data)
6565
* [Lists all databases on the selected instance](#lists-all-databases-on-the-selected-instance)
6666
* [Lists all the available instance configs for the selected project.](#lists-all-the-available-instance-configs-for-the-selected-project.)
67+
* [Executes request with max commit delay](#executes-request-with-max-commit-delay)
6768
* [Numeric-add-column](#numeric-add-column)
6869
* [Numeric-query-parameter](#numeric-query-parameter)
6970
* [Numeric-update-data](#numeric-update-data)
@@ -978,6 +979,23 @@ __Usage:__
978979

979980

980981

982+
### Executes request with max commit delay
983+
984+
View the [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/max-commit-delay.js).
985+
986+
[![Open in Cloud Shell][shell_img]](https://console.cloud.google.com/cloudshell/open?git_repo=https://github.com/googleapis/nodejs-spanner&page=editor&open_in_editor=samples/max-commit-delay.js,samples/README.md)
987+
988+
__Usage:__
989+
990+
991+
`node max-commit-delay.js <INSTANCE_ID> <DATABASE_ID> <PROJECT_ID>`
992+
993+
994+
-----
995+
996+
997+
998+
981999
### Numeric-add-column
9821000

9831001
View the [source code](https://github.com/googleapis/nodejs-spanner/blob/main/samples/numeric-add-column.js).

samples/max-commit-delay.js

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
// sample-metadata:
15+
// title: Executes request with max commit delay
16+
// usage: node max-commit-delay.js <INSTANCE_ID> <DATABASE_ID> <PROJECT_ID>
17+
18+
'use strict';
19+
20+
function main(
21+
instanceId = 'my-instance',
22+
databaseId = 'my-database',
23+
projectId = 'my-project-id'
24+
) {
25+
// [START spanner_set_max_commit_delay]
26+
// Imports the Google Cloud client library.
27+
const {Spanner, protos} = require('@google-cloud/spanner');
28+
29+
/**
30+
* TODO(developer): Uncomment the following lines before running the sample.
31+
*/
32+
// const projectId = 'my-project-id';
33+
// const instanceId = 'my-instance';
34+
// const databaseId = 'my-database';
35+
36+
// Creates a client.
37+
const spanner = new Spanner({
38+
projectId: projectId,
39+
});
40+
41+
async function spannerSetMaxCommitDelay() {
42+
// Gets a reference to a Cloud Spanner instance and database.
43+
const instance = spanner.instance(instanceId);
44+
const database = instance.database(databaseId);
45+
46+
database.runTransaction(async (err, transaction) => {
47+
if (err) {
48+
console.error(err);
49+
return;
50+
}
51+
try {
52+
const [rowCount] = await transaction.runUpdate({
53+
sql: 'INSERT Singers (SingerId, FirstName, LastName) VALUES (111, @firstName, @lastName)',
54+
params: {
55+
firstName: 'Virginia',
56+
lastName: 'Watson',
57+
},
58+
});
59+
60+
console.log(
61+
`Successfully inserted ${rowCount} record into the Singers table.`
62+
);
63+
64+
await transaction.commit({
65+
// The maximum amount of time to delay the transaction to improve
66+
// throughput.
67+
maxCommitDelay: protos.google.protobuf.Duration({
68+
seconds: 0, // 0 seconds
69+
nanos: 100000000, // 100,000,000 nanoseconds = 100 milliseconds
70+
}),
71+
});
72+
} catch (err) {
73+
console.error('ERROR:', err);
74+
} finally {
75+
// Close the database when finished.
76+
database.close();
77+
}
78+
});
79+
}
80+
spannerSetMaxCommitDelay();
81+
// [END spanner_set_max_commit_delay]
82+
}
83+
process.on('unhandledRejection', err => {
84+
console.error(err.message);
85+
process.exitCode = 1;
86+
});
87+
main(...process.argv.slice(2));

samples/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
"node": ">=14.0.0"
1212
},
1313
"scripts": {
14-
"test": "mocha system-test --timeout 1600000"
14+
"test-with-archived": "mocha system-test --timeout 1600000",
15+
"test": "mocha system-test/spanner.test.js --timeout 1600000"
1516
},
1617
"dependencies": {
1718
"@google-cloud/kms": "^4.0.0",
1819
"@google-cloud/precise-date": "^4.0.0",
19-
"@google-cloud/spanner": "^7.5.0",
20+
"@google-cloud/spanner": "^7.6.0",
2021
"yargs": "^17.0.0"
2122
},
2223
"devDependencies": {

samples/schema.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,20 @@ async function createDatabase(instanceID, databaseID, projectID) {
3737
const databaseAdminClient = spanner.getDatabaseAdminClient();
3838

3939
const createSingersTableStatement = `
40-
CREATE TABLE Singers (
41-
SingerId INT64 NOT NULL,
42-
FirstName STRING(1024),
43-
LastName STRING(1024),
44-
SingerInfo BYTES(MAX)
45-
) PRIMARY KEY (SingerId)`;
40+
CREATE TABLE Singers (
41+
SingerId INT64 NOT NULL,
42+
FirstName STRING(1024),
43+
LastName STRING(1024),
44+
SingerInfo BYTES(MAX),
45+
FullName STRING(2048) AS (ARRAY_TO_STRING([FirstName, LastName], " ")) STORED,
46+
) PRIMARY KEY (SingerId)`;
4647
const createAlbumsTableStatement = `
47-
CREATE TABLE Albums (
48-
SingerId INT64 NOT NULL,
49-
AlbumId INT64 NOT NULL,
50-
AlbumTitle STRING(MAX)
51-
) PRIMARY KEY (SingerId, AlbumId),
52-
INTERLEAVE IN PARENT Singers ON DELETE CASCADE`;
48+
CREATE TABLE Albums (
49+
SingerId INT64 NOT NULL,
50+
AlbumId INT64 NOT NULL,
51+
AlbumTitle STRING(MAX)
52+
) PRIMARY KEY (SingerId, AlbumId),
53+
INTERLEAVE IN PARENT Singers ON DELETE CASCADE`;
5354

5455
// Creates a new database
5556
try {

0 commit comments

Comments
 (0)