Ensure the example code snippet compiles again
There were 2 errors when using the example code: - not enough arguments in call to pgConn.Close - no new variables on left side of := With these changes, the example works again.
This commit is contained in:
committed by
Jack Christensen
parent
416f037e77
commit
f3f5b70a87
@@ -15,16 +15,16 @@ pgConn, err := pgconn.Connect(context.Background(), os.Getenv("DATABASE_URL"))
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln("pgconn failed to connect:", err)
|
log.Fatalln("pgconn failed to connect:", err)
|
||||||
}
|
}
|
||||||
defer pgConn.Close()
|
defer pgConn.Close(context.Background())
|
||||||
|
|
||||||
result := pgConn.ExecParams(context.Background(), "SELECT email FROM users WHERE id=$1", [][]byte{[]byte("123")}, nil, nil, nil)
|
result := pgConn.ExecParams(context.Background(), "SELECT email FROM users WHERE id=$1", [][]byte{[]byte("123")}, nil, nil, nil)
|
||||||
for result.NextRow() {
|
for result.NextRow() {
|
||||||
fmt.Println("User 123 has email:", string(result.Values()[0]))
|
fmt.Println("User 123 has email:", string(result.Values()[0]))
|
||||||
}
|
}
|
||||||
_, err := result.Close()
|
_, err = result.Close()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalln("failed reading result:", err)
|
log.Fatalln("failed reading result:", err)
|
||||||
})
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Testing
|
## Testing
|
||||||
|
|||||||
Reference in New Issue
Block a user