Skip to content

Commit b4803a6

Browse files
authored
docs: add missing conn.Close() calls (#324)
Some of the examples missed a call to conn.Close(). Updates googleapis/google-cloud-go#11017
1 parent 3c45d27 commit b4803a6

File tree

5 files changed

+5
-0
lines changed

5 files changed

+5
-0
lines changed

examples/ddl-batches/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func ddlBatches(projectId, instanceId, databaseId string) error {
5050
if err != nil {
5151
return fmt.Errorf("failed to get connection: %v", err)
5252
}
53+
defer conn.Close()
5354
// Start a DDL batch on the connection.
5455
if _, err := conn.ExecContext(ctx, "START BATCH DDL"); err != nil {
5556
return fmt.Errorf("START BATCH DDL failed: %v", err)

examples/dml-batches/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ func dmlBatch(projectId, instanceId, databaseId string) error {
8989
if err != nil {
9090
return fmt.Errorf("failed to get connection: %v", err)
9191
}
92+
defer conn.Close()
9293
if err := conn.Raw(func(driverConn interface{}) error {
9394
return driverConn.(spannerdriver.SpannerConn).StartBatchDML()
9495
}); err != nil {

examples/mutations/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func mutations(projectId, instanceId, databaseId string) error {
4444
if err != nil {
4545
return err
4646
}
47+
defer conn.Close()
4748

4849
// Mutations can be written outside an explicit transaction using SpannerConn#Apply.
4950
var commitTimestamp time.Time

examples/partitioned-dml/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ func partitionedDml(projectId, instanceId, databaseId string) error {
4343
if err != nil {
4444
return fmt.Errorf("failed to get a connection: %v", err)
4545
}
46+
defer conn.Close()
4647
if err := conn.Raw(func(driverConn interface{}) error {
4748
_, err := driverConn.(spannerdriver.SpannerConn).Apply(ctx, []*spanner.Mutation{
4849
spanner.InsertOrUpdateMap("Singers", map[string]interface{}{"SingerId": 1, "Name": "Singer 1"}),

examples/stale-reads/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ func staleReads(projectId, instanceId, databaseId string) error {
6565
if err != nil {
6666
return err
6767
}
68+
defer conn.Close()
6869
if _, err := conn.ExecContext(ctx, fmt.Sprintf("SET READ_ONLY_STALENESS='READ_TIMESTAMP %s'", t.Format(time.RFC3339Nano))); err != nil {
6970
return err
7071
}

0 commit comments

Comments
 (0)