shad-go/lectures/07-sql/named/insert.go

19 lines
263 B
Go
Raw Normal View History

2020-04-09 11:15:34 +00:00
package named
import (
"context"
"database/sql"
"log"
2020-04-08 19:20:23 +00:00
)
2020-04-09 11:15:34 +00:00
func Insert(ctx context.Context, db *sql.DB) {
_, err := db.ExecContext(
ctx,
"INSERT INTO users(name) VALUES(@name)",
sql.Named("name", "Amos Burton"),
)
if err != nil {
log.Fatal(err)
}
}