133 lines
2.8 KiB
Go
133 lines
2.8 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.28.0
|
|
// source: users.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const createUser = `-- name: CreateUser :one
|
|
INSERT INTO users (username, password_hash)
|
|
VALUES ($1, $2)
|
|
RETURNING id, username, password_hash, is_admin, created_at, updated_at
|
|
`
|
|
|
|
type CreateUserParams struct {
|
|
Username string `json:"username"`
|
|
PasswordHash string `json:"password_hash"`
|
|
}
|
|
|
|
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, error) {
|
|
row := q.db.QueryRow(ctx, createUser, arg.Username, arg.PasswordHash)
|
|
var i User
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Username,
|
|
&i.PasswordHash,
|
|
&i.IsAdmin,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteUser = `-- name: DeleteUser :exec
|
|
DELETE FROM users
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteUser(ctx context.Context, id uuid.UUID) error {
|
|
_, err := q.db.Exec(ctx, deleteUser, id)
|
|
return err
|
|
}
|
|
|
|
const getUserByID = `-- name: GetUserByID :one
|
|
SELECT id, username, password_hash, is_admin, created_at, updated_at FROM users
|
|
WHERE id = $1 LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetUserByID(ctx context.Context, id uuid.UUID) (User, error) {
|
|
row := q.db.QueryRow(ctx, getUserByID, id)
|
|
var i User
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Username,
|
|
&i.PasswordHash,
|
|
&i.IsAdmin,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getUserByUsername = `-- name: GetUserByUsername :one
|
|
SELECT id, username, password_hash, is_admin, created_at, updated_at FROM users
|
|
WHERE username = $1 LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) GetUserByUsername(ctx context.Context, username string) (User, error) {
|
|
row := q.db.QueryRow(ctx, getUserByUsername, username)
|
|
var i User
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Username,
|
|
&i.PasswordHash,
|
|
&i.IsAdmin,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listUsers = `-- name: ListUsers :many
|
|
SELECT id, username, password_hash, is_admin, created_at, updated_at FROM users
|
|
`
|
|
|
|
func (q *Queries) ListUsers(ctx context.Context) ([]User, error) {
|
|
rows, err := q.db.Query(ctx, listUsers)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []User
|
|
for rows.Next() {
|
|
var i User
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Username,
|
|
&i.PasswordHash,
|
|
&i.IsAdmin,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const updatePassword = `-- name: UpdatePassword :exec
|
|
UPDATE users
|
|
SET password_hash = $2, updated_at = NOW()
|
|
WHERE id = $1
|
|
`
|
|
|
|
type UpdatePasswordParams struct {
|
|
ID uuid.UUID `json:"id"`
|
|
PasswordHash string `json:"password_hash"`
|
|
}
|
|
|
|
func (q *Queries) UpdatePassword(ctx context.Context, arg UpdatePasswordParams) error {
|
|
_, err := q.db.Exec(ctx, updatePassword, arg.ID, arg.PasswordHash)
|
|
return err
|
|
}
|