MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / deleteUsingPartitionedDml

Function deleteUsingPartitionedDml

spanner/dml.js:501–534  ·  view source on GitHub ↗
(instanceId, databaseId, projectId)

Source from the content-addressed store, hash-verified

499}
500
501async function deleteUsingPartitionedDml(instanceId, databaseId, projectId) {
502 // [START spanner_dml_partitioned_delete]
503 // Imports the Google Cloud client library
504 const {Spanner} = require('@google-cloud/spanner');
505
506 /**
507 * TODO(developer): Uncomment the following lines before running the sample.
508 */
509 // const projectId = 'my-project-id';
510 // const instanceId = 'my-instance';
511 // const databaseId = 'my-database';
512
513 // Creates a client
514 const spanner = new Spanner({
515 projectId: projectId,
516 });
517
518 // Gets a reference to a Cloud Spanner instance and database
519 const instance = spanner.instance(instanceId);
520 const database = instance.database(databaseId);
521
522 try {
523 const [rowCount] = await database.runPartitionedUpdate({
524 sql: 'DELETE FROM Singers WHERE SingerId > 10',
525 });
526 console.log(`Successfully deleted ${rowCount} records.`);
527 } catch (err) {
528 console.error('ERROR:', err);
529 } finally {
530 // Close the database when finished.
531 await database.close();
532 }
533 // [END spanner_dml_partitioned_delete]
534}
535
536async function updateUsingBatchDml(instanceId, databaseId, projectId) {
537 // [START spanner_dml_batch_update]

Callers 1

dml.jsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected