Skip to content

Commit

Permalink
docs: add missing conn.Close() calls (#324)
Browse files Browse the repository at this point in the history
Some of the examples missed a call to conn.Close().

Updates googleapis/google-cloud-go#11017
  • Loading branch information
olavloite authored Nov 18, 2024
1 parent 3c45d27 commit b4803a6
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/ddl-batches/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions examples/dml-batches/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions examples/mutations/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions examples/partitioned-dml/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}),
Expand Down
1 change: 1 addition & 0 deletions examples/stale-reads/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit b4803a6

Please sign in to comment.