Refactoring for Gin, NoSurf and SCS continues.
This commit is contained in:
22
internal/storage/users/create.go
Normal file
22
internal/storage/users/create.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package storage
|
||||
|
||||
// ToDo.. "errors" should this not be using my custom log wrapper
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
type UsersRepo struct{ db *sql.DB }
|
||||
|
||||
func NewUsersRepo(db *sql.DB) *UsersRepo {
|
||||
return &UsersRepo{db: db}
|
||||
}
|
||||
|
||||
// ToDo: should the function be in sql?
|
||||
func (r *UsersRepo) Create(ctx context.Context, username, passwordHash string, isAdmin bool) error {
|
||||
_, err := r.db.ExecContext(ctx,
|
||||
`INSERT INTO users (username, password_hash, is_admin) VALUES (?, ?, ?)`,
|
||||
username, passwordHash, isAdmin,
|
||||
)
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user