shad-go/lectures/07-sql/exec/exec.go
2021-04-08 14:39:10 +03:00

23 lines
363 B
Go

package exec
import (
"context"
"database/sql"
"log"
)
func Exec(ctx context.Context, db *sql.DB) {
res, err := db.ExecContext(
ctx,
"UPDATE users SET name = $1 WHERE id = $2",
"William Mandella", 1,
)
if err != nil {
log.Fatal(err)
}
lastID, _ := res.LastInsertId()
rowsAffected, _ := res.RowsAffected()
log.Println(lastID, rowsAffected)
}