114 lines
2.3 KiB
Go
114 lines
2.3 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: users.sql
|
|
|
|
package database
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
const createUser = `-- name: CreateUser :one
|
|
INSERT INTO users (id, created_at, updated_at, email, hashed_password)
|
|
VALUES (
|
|
gen_random_uuid(),
|
|
NOW(),
|
|
NOW(),
|
|
$1,
|
|
$2
|
|
)
|
|
RETURNING id, created_at, updated_at, email, hashed_password
|
|
`
|
|
|
|
type CreateUserParams struct {
|
|
Email string
|
|
HashedPassword string
|
|
}
|
|
|
|
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, error) {
|
|
row := q.db.QueryRowContext(ctx, createUser, arg.Email, arg.HashedPassword)
|
|
var i User
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.Email,
|
|
&i.HashedPassword,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteAllUsers = `-- name: DeleteAllUsers :exec
|
|
DELETE FROM users
|
|
`
|
|
|
|
func (q *Queries) DeleteAllUsers(ctx context.Context) error {
|
|
_, err := q.db.ExecContext(ctx, deleteAllUsers)
|
|
return err
|
|
}
|
|
|
|
const getUserByEmail = `-- name: GetUserByEmail :one
|
|
SELECT id, created_at, updated_at, email, hashed_password FROM users
|
|
WHERE email = $1
|
|
`
|
|
|
|
func (q *Queries) GetUserByEmail(ctx context.Context, email string) (User, error) {
|
|
row := q.db.QueryRowContext(ctx, getUserByEmail, email)
|
|
var i User
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.Email,
|
|
&i.HashedPassword,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getUserById = `-- name: GetUserById :one
|
|
SELECT id, created_at, updated_at, email, hashed_password FROM users
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetUserById(ctx context.Context, id uuid.UUID) (User, error) {
|
|
row := q.db.QueryRowContext(ctx, getUserById, id)
|
|
var i User
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.Email,
|
|
&i.HashedPassword,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const updateUser = `-- name: UpdateUser :one
|
|
UPDATE users
|
|
SET email = $2, hashed_password = $3, updated_at = NOW()
|
|
WHERE id = $1
|
|
RETURNING id, created_at, updated_at, email, hashed_password
|
|
`
|
|
|
|
type UpdateUserParams struct {
|
|
ID uuid.UUID
|
|
Email string
|
|
HashedPassword string
|
|
}
|
|
|
|
func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) (User, error) {
|
|
row := q.db.QueryRowContext(ctx, updateUser, arg.ID, arg.Email, arg.HashedPassword)
|
|
var i User
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.Email,
|
|
&i.HashedPassword,
|
|
)
|
|
return i, err
|
|
}
|