GoogleCloudPlatform / node-red-contrib-google-cloud

Node-RED nodes for Google Cloud Platform
Apache License 2.0
90 stars 57 forks source link

Cloud Spanner nodes #93

Closed kolban-google closed 3 years ago

kolban-google commented 3 years ago

Cloud Spanner is a Google RDBMS that provides a global transactional database. This issue requests the creation of a new node or nodes for Cloud Spanner interaction.

At first blush, it appears that we want a node that will execute SQL statements supplied in string format. While the statements are supplied as String SQL, we need two configuration parameters at the node level. These appear to be:

The high level access code looks to be:

const {Spanner} = require('@google-cloud/spanner');
const spanner = new Spanner({
  projectId: projectId,
});
const instance = spanner.instance(instanceId);
const database = instance.database(databaseId);
const query = {
  sql: 'SELECT SingerId, AlbumId, AlbumTitle FROM Albums',
};
const [rows] = await database.run(query);

The key to the story is the database.run() function call documented here.

There are a rich set of additional options to Spanner but these are currently not in scope. Items in this list would include

Node spec

Node name: Spanner Run

Configuration parameters:

Execution When the node is reached, if a value is present in "SQL statements", the execution will use that value. If not present, the execution will use the value contained in msg.payload. On completion, the output will be found in msg.payload. The actual output will depend on the statements executes but for a query will be an array of records.

References

kolban-google commented 3 years ago

First implementation published in 0.0.24

kolban-google commented 3 years ago

A user tested and came back and said it worked. LGTM.