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

22 lines
303 B
Go
Raw Normal View History

2020-04-09 11:15:34 +00:00
package sqlx
import (
"context"
"log"
"github.com/jmoiron/sqlx"
)
func Insert(ctx context.Context, db *sqlx.DB) {
_, err := db.NamedExecContext(
ctx,
"INSERT INTO users(name) VALUES(:name)",
map[string]interface{}{
"name": "Jukka Sarasti",
},
)
if err != nil {
log.Fatal(err)
}
}