Skip to content

Commit

Permalink
Merge branch 'master' into improve_streams
Browse files Browse the repository at this point in the history
  • Loading branch information
AVaksman authored Jun 8, 2020
2 parents 0d73134 + 57106a7 commit d81ca44
Show file tree
Hide file tree
Showing 22 changed files with 585 additions and 56 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ system-test/*key.json
.DS_Store
package-lock.json
__pycache__
.idea
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@

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

## [5.1.0](https://www.github.com/googleapis/nodejs-spanner/compare/v5.0.0...v5.1.0) (2020-06-04)


### Features

* expose displayName in createInstance ([#798](https://www.github.com/googleapis/nodejs-spanner/issues/798)) ([39efda1](https://www.github.com/googleapis/nodejs-spanner/commit/39efda194d2d11a578f209e6c149b0ae2974ee27))
* increase sessions in the pool in batches ([#963](https://www.github.com/googleapis/nodejs-spanner/issues/963)) ([91c53cb](https://www.github.com/googleapis/nodejs-spanner/commit/91c53cb6f6504f48ee3c974dbb8fb2821c226325))
* support callbacks for exists(), getState(), getExpireTime() methods ([#1070](https://www.github.com/googleapis/nodejs-spanner/issues/1070)) ([7736080](https://www.github.com/googleapis/nodejs-spanner/commit/7736080f0e2a46c7ef8c44c278bff2bec2f28953))


### Bug Fixes

* always clean up stale instances if any ([#1030](https://www.github.com/googleapis/nodejs-spanner/issues/1030)) ([87c7edc](https://www.github.com/googleapis/nodejs-spanner/commit/87c7edcb2c3ba729b1e278bb191b695b0cd376cb))
* pause request stream on backpressure ([#936](https://www.github.com/googleapis/nodejs-spanner/issues/936)) ([558692f](https://www.github.com/googleapis/nodejs-spanner/commit/558692f55cc551db2bd72464b130051a9b28378f)), closes [#934](https://www.github.com/googleapis/nodejs-spanner/issues/934)

## [5.0.0](https://www.github.com/googleapis/nodejs-spanner/compare/v4.8.0...v5.0.0) (2020-05-14)


Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@google-cloud/spanner",
"description": "Cloud Spanner Client Library for Node.js",
"version": "5.0.0",
"version": "5.1.0",
"license": "Apache-2.0",
"author": "Google Inc.",
"engines": {
Expand Down Expand Up @@ -108,7 +108,7 @@
"retry-request": "^4.1.1",
"sinon": "^9.0.0",
"stats-lite": "^2.1.1",
"teeny-request": "^6.0.3",
"teeny-request": "^7.0.0",
"time-span": "^4.0.0",
"tmp": "^0.2.0",
"typescript": "^3.8.3",
Expand Down
6 changes: 6 additions & 0 deletions protos/protos.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,9 @@ export namespace google {

/** FieldDescriptorProto options */
options?: (google.protobuf.IFieldOptions|null);

/** FieldDescriptorProto proto3Optional */
proto3Optional?: (boolean|null);
}

/** Represents a FieldDescriptorProto. */
Expand Down Expand Up @@ -870,6 +873,9 @@ export namespace google {
/** FieldDescriptorProto options. */
public options?: (google.protobuf.IFieldOptions|null);

/** FieldDescriptorProto proto3Optional. */
public proto3Optional: boolean;

/**
* Creates a new FieldDescriptorProto instance using the specified properties.
* @param [properties] Properties to set
Expand Down
26 changes: 24 additions & 2 deletions protos/protos.js
Original file line number Diff line number Diff line change
Expand Up @@ -2291,6 +2291,7 @@
* @property {number|null} [oneofIndex] FieldDescriptorProto oneofIndex
* @property {string|null} [jsonName] FieldDescriptorProto jsonName
* @property {google.protobuf.IFieldOptions|null} [options] FieldDescriptorProto options
* @property {boolean|null} [proto3Optional] FieldDescriptorProto proto3Optional
*/

/**
Expand Down Expand Up @@ -2388,6 +2389,14 @@
*/
FieldDescriptorProto.prototype.options = null;

/**
* FieldDescriptorProto proto3Optional.
* @member {boolean} proto3Optional
* @memberof google.protobuf.FieldDescriptorProto
* @instance
*/
FieldDescriptorProto.prototype.proto3Optional = false;

/**
* Creates a new FieldDescriptorProto instance using the specified properties.
* @function create
Expand Down Expand Up @@ -2432,6 +2441,8 @@
writer.uint32(/* id 9, wireType 0 =*/72).int32(message.oneofIndex);
if (message.jsonName != null && Object.hasOwnProperty.call(message, "jsonName"))
writer.uint32(/* id 10, wireType 2 =*/82).string(message.jsonName);
if (message.proto3Optional != null && Object.hasOwnProperty.call(message, "proto3Optional"))
writer.uint32(/* id 17, wireType 0 =*/136).bool(message.proto3Optional);
return writer;
};

Expand Down Expand Up @@ -2496,6 +2507,9 @@
case 8:
message.options = $root.google.protobuf.FieldOptions.decode(reader, reader.uint32());
break;
case 17:
message.proto3Optional = reader.bool();
break;
default:
reader.skipType(tag & 7);
break;
Expand Down Expand Up @@ -2590,6 +2604,9 @@
if (error)
return "options." + error;
}
if (message.proto3Optional != null && message.hasOwnProperty("proto3Optional"))
if (typeof message.proto3Optional !== "boolean")
return "proto3Optional: boolean expected";
return null;
};

Expand Down Expand Up @@ -2712,6 +2729,8 @@
throw TypeError(".google.protobuf.FieldDescriptorProto.options: object expected");
message.options = $root.google.protobuf.FieldOptions.fromObject(object.options);
}
if (object.proto3Optional != null)
message.proto3Optional = Boolean(object.proto3Optional);
return message;
};

Expand Down Expand Up @@ -2739,6 +2758,7 @@
object.options = null;
object.oneofIndex = 0;
object.jsonName = "";
object.proto3Optional = false;
}
if (message.name != null && message.hasOwnProperty("name"))
object.name = message.name;
Expand All @@ -2760,6 +2780,8 @@
object.oneofIndex = message.oneofIndex;
if (message.jsonName != null && message.hasOwnProperty("jsonName"))
object.jsonName = message.jsonName;
if (message.proto3Optional != null && message.hasOwnProperty("proto3Optional"))
object.proto3Optional = message.proto3Optional;
return object;
};

Expand Down Expand Up @@ -4553,7 +4575,7 @@
* @memberof google.protobuf.FileOptions
* @instance
*/
FileOptions.prototype.ccEnableArenas = false;
FileOptions.prototype.ccEnableArenas = true;

/**
* FileOptions objcClassPrefix.
Expand Down Expand Up @@ -5039,7 +5061,7 @@
object.javaGenerateEqualsAndHash = false;
object.deprecated = false;
object.javaStringCheckUtf8 = false;
object.ccEnableArenas = false;
object.ccEnableArenas = true;
object.objcClassPrefix = "";
object.csharpNamespace = "";
object.swiftPrefix = "";
Expand Down
6 changes: 5 additions & 1 deletion protos/protos.json
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@
"options": {
"type": "FieldOptions",
"id": 8
},
"proto3Optional": {
"type": "bool",
"id": 17
}
},
"nested": {
Expand Down Expand Up @@ -472,7 +476,7 @@
"type": "bool",
"id": 31,
"options": {
"default": false
"default": true
}
},
"objcClassPrefix": {
Expand Down
57 changes: 49 additions & 8 deletions samples/crud.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,19 +134,60 @@ async function deleteData(instanceId, databaseId, projectId) {
const database = instance.database(databaseId);

// Instantiate Spanner table object
const singersTable = database.table('Singers');
const albumsTable = database.table('Albums');

// Deletes rows from the Singers table and the Albums table,
// because Albums table is defined with ON DELETE CASCADE.
// Deletes individual rows from the Albums table.
try {
const keys = [1, 2, 3, 4, 5];
await singersTable.deleteRows(keys);
console.log('Deleted data.');
const keys = [
[2, 1],
[2, 3],
];
await albumsTable.deleteRows(keys);
console.log('Deleted individual rows in Albums.');
} catch (err) {
console.error('ERROR:', err);
} finally {
await database.close();
}

// Delete a range of rows where the column key is >=3 and <5
database.runTransaction(async (err, transaction) => {
if (err) {
console.error(err);
return;
}
try {
const [rowCount] = await transaction.runUpdate({
sql: 'DELETE FROM Singers WHERE SingerId >= 3 AND SingerId < 5',
});
console.log(`${rowCount} records deleted from Singers.`);
await transaction.commit();
} catch (err) {
console.error('ERROR:', err);
}
});

// Deletes remaining rows from the Singers table and the Albums table,
// because Albums table is defined with ON DELETE CASCADE.
database.runTransaction(async (err, transaction) => {
if (err) {
console.error(err);
return;
}
try {
// The WHERE clause is required for DELETE statements to prevent
// accidentally deleting all rows in a table.
// https://cloud.google.com/spanner/docs/dml-syntax#where_clause
const [rowCount] = await transaction.runUpdate({
sql: 'DELETE FROM Singers WHERE true',
});
console.log(`${rowCount} records deleted from Singers.`);
await transaction.commit();
} catch (err) {
console.error('ERROR:', err);
} finally {
// Close the database when finished.
await database.close();
}
});
// [END spanner_delete_data]
}

Expand Down
71 changes: 71 additions & 0 deletions samples/instance.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/**
* Copyright 2020 Google LLC
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

async function createInstance(instanceId, projectId) {
// [START spanner_create_instance]
// Imports the Google Cloud client library
const {Spanner} = require('@google-cloud/spanner');

/**
* TODO(developer): Uncomment the following lines before running the sample.
*/
// const projectId = 'my-project-id';
// const instanceId = 'my-instance';

// Creates a client
const spanner = new Spanner({
projectId: projectId,
});

const instance = spanner.instance(instanceId);

// Creates a new instance
try {
console.log(`Creating instance ${instance.formattedName_}.`);
const [, operation] = await instance.create({
config: 'regional-us-central1',
nodes: 2,
displayName: instanceId,
labels: {
['cloud_spanner_samples']: 'true',
},
});

console.log(`Waiting for operation on ${instance.id} to complete...`);
await operation.promise();

console.log(`Created instance ${instanceId}.`);
} catch (err) {
console.error('ERROR:', err);
}
// [END spanner_create_instance]
}

require('yargs')
.demand(1)
.command(
'createInstance <instanceName> <projectId>',
'Creates an example instance in a Cloud Spanner instance.',
{},
opts => createInstance(opts.instanceName, opts.projectId)
)
.example('node $0 createInstance "my-instance" "my-project-id"')
.wrap(120)
.recommendCommands()
.epilogue('For more information, see https://cloud.google.com/spanner/docs')
.strict()
.help().argv;
2 changes: 1 addition & 1 deletion samples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
},
"dependencies": {
"@google-cloud/precise-date": "^1.0.0",
"@google-cloud/spanner": "^5.0.0",
"@google-cloud/spanner": "^5.1.0",
"yargs": "^15.0.0"
},
"devDependencies": {
Expand Down
31 changes: 30 additions & 1 deletion samples/system-test/spanner.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const structCmd = 'node struct.js';
const dmlCmd = 'node dml.js';
const datatypesCmd = 'node datatypes.js';
const backupsCmd = 'node backups.js';
const instanceCmd = 'node instance.js';

const date = Date.now();
const PROJECT_ID = process.env.GCLOUD_PROJECT;
Expand Down Expand Up @@ -127,6 +128,32 @@ describe('Spanner', () => {
}
});

describe('instance', () => {
const SAMPLE_INSTANCE_ID = 'my-sample-instance';

after(async () => {
const sample_instance = spanner.instance(SAMPLE_INSTANCE_ID);
await sample_instance.delete();
});

// create_instance
it('should create an example instance', async () => {
const output = execSync(
`${instanceCmd} createInstance "${SAMPLE_INSTANCE_ID}" ${PROJECT_ID}`
);
assert.match(
output,
new RegExp(
`Waiting for operation on ${SAMPLE_INSTANCE_ID} to complete...`
)
);
assert.match(
output,
new RegExp(`Created instance ${SAMPLE_INSTANCE_ID}.`)
);
});
});

// create_database
it('should create an example database', async () => {
const output = execSync(
Expand Down Expand Up @@ -166,7 +193,9 @@ describe('Spanner', () => {
let output = execSync(
`${crudCmd} delete ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`
);
assert.match(output, /Deleted data\./);
assert.include(output, 'Deleted individual rows in Albums.');
assert.include(output, '2 records deleted from Singers.');
assert.include(output, '3 records deleted from Singers.');
output = execSync(
`${crudCmd} insert ${INSTANCE_ID} ${DATABASE_ID} ${PROJECT_ID}`
);
Expand Down
Loading

0 comments on commit d81ca44

Please sign in to comment.