-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
33 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package sqlx_examples | ||
|
||
import ( | ||
"log" | ||
"strings" | ||
) | ||
|
||
func correctSqlCloseCheckG[T ~int64]() { | ||
age := 27 | ||
rows, err := db.Queryx("SELECT name FROM users WHERE age=?", age) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
defer rows.Close() | ||
|
||
names := make([]string, 0) | ||
for rows.Next() { | ||
var name string | ||
if err := rows.Scan(&name); err != nil { | ||
log.Fatal(err) | ||
} | ||
names = append(names, name) | ||
} | ||
|
||
// Check for errors from iterating over rows. | ||
if err := rows.Err(); err != nil { | ||
log.Fatal(err) | ||
} | ||
log.Printf("%s are %d years old", strings.Join(names, ", "), age) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters