From ae2dd114c5bb3e3fe09f8b080e34ed4bcab5ef80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Knut=20Olav=20L=C3=B8ite?= Date: Mon, 18 Nov 2024 09:32:28 +0100 Subject: [PATCH] docs: add missing conn.Close() calls Some of the examples missed a call to conn.Close(). Updates https://github.com/googleapis/google-cloud-go/issues/11017 --- examples/ddl-batches/main.go | 1 + examples/dml-batches/main.go | 1 + examples/mutations/main.go | 1 + examples/partitioned-dml/main.go | 1 + examples/stale-reads/main.go | 1 + 5 files changed, 5 insertions(+) diff --git a/examples/ddl-batches/main.go b/examples/ddl-batches/main.go index 7c5102b8..a0fc3201 100644 --- a/examples/ddl-batches/main.go +++ b/examples/ddl-batches/main.go @@ -50,6 +50,7 @@ func ddlBatches(projectId, instanceId, databaseId string) error { if err != nil { return fmt.Errorf("failed to get connection: %v", err) } + defer conn.Close() // Start a DDL batch on the connection. if _, err := conn.ExecContext(ctx, "START BATCH DDL"); err != nil { return fmt.Errorf("START BATCH DDL failed: %v", err) diff --git a/examples/dml-batches/main.go b/examples/dml-batches/main.go index 026144d3..f5eeaa51 100644 --- a/examples/dml-batches/main.go +++ b/examples/dml-batches/main.go @@ -89,6 +89,7 @@ func dmlBatch(projectId, instanceId, databaseId string) error { if err != nil { return fmt.Errorf("failed to get connection: %v", err) } + defer conn.Close() if err := conn.Raw(func(driverConn interface{}) error { return driverConn.(spannerdriver.SpannerConn).StartBatchDML() }); err != nil { diff --git a/examples/mutations/main.go b/examples/mutations/main.go index 32de4b2e..c1dae91c 100644 --- a/examples/mutations/main.go +++ b/examples/mutations/main.go @@ -44,6 +44,7 @@ func mutations(projectId, instanceId, databaseId string) error { if err != nil { return err } + defer conn.Close() // Mutations can be written outside an explicit transaction using SpannerConn#Apply. var commitTimestamp time.Time diff --git a/examples/partitioned-dml/main.go b/examples/partitioned-dml/main.go index a284a43e..ab70f7cd 100644 --- a/examples/partitioned-dml/main.go +++ b/examples/partitioned-dml/main.go @@ -43,6 +43,7 @@ func partitionedDml(projectId, instanceId, databaseId string) error { if err != nil { return fmt.Errorf("failed to get a connection: %v", err) } + defer conn.Close() if err := conn.Raw(func(driverConn interface{}) error { _, err := driverConn.(spannerdriver.SpannerConn).Apply(ctx, []*spanner.Mutation{ spanner.InsertOrUpdateMap("Singers", map[string]interface{}{"SingerId": 1, "Name": "Singer 1"}), diff --git a/examples/stale-reads/main.go b/examples/stale-reads/main.go index 6c19fa08..e7f2fe68 100644 --- a/examples/stale-reads/main.go +++ b/examples/stale-reads/main.go @@ -65,6 +65,7 @@ func staleReads(projectId, instanceId, databaseId string) error { if err != nil { return err } + defer conn.Close() if _, err := conn.ExecContext(ctx, fmt.Sprintf("SET READ_ONLY_STALENESS='READ_TIMESTAMP %s'", t.Format(time.RFC3339Nano))); err != nil { return err }