chirpy_server/internal/database/users.sql.go

130 lines
2.7 KiB
Go
Raw Permalink Normal View History

2024-10-23 22:16:51 +02:00
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.27.0
// source: users.sql
package database
import (
"context"
"time"
2024-10-26 15:03:14 +02:00
"github.com/google/uuid"
2024-10-23 22:16:51 +02:00
)
const createUser = `-- name: CreateUser :one
INSERT INTO users (id, created_at, updated_at, email, hashed_password)
2024-10-23 22:16:51 +02:00
VALUES (
gen_random_uuid(),
NOW(),
NOW(),
$1,
2024-10-25 23:31:57 +02:00
$2
2024-10-23 22:16:51 +02:00
)
2024-10-26 15:03:14 +02:00
RETURNING id, created_at, updated_at, email, hashed_password, is_chirpy_red
2024-10-23 22:16:51 +02:00
`
2024-10-25 23:31:57 +02:00
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)
2024-10-23 22:16:51 +02:00
var i User
err := row.Scan(
&i.ID,
&i.CreatedAt,
&i.UpdatedAt,
&i.Email,
&i.HashedPassword,
2024-10-26 15:03:14 +02:00
&i.IsChirpyRed,
2024-10-23 22:16:51 +02:00
)
return i, err
}
const deleteUser = `-- name: DeleteUser :one
DELETE FROM users
2024-10-26 15:03:14 +02:00
RETURNING id, created_at, updated_at, email, hashed_password, is_chirpy_red
2024-10-23 22:16:51 +02:00
`
func (q *Queries) DeleteUser(ctx context.Context) (User, error) {
row := q.db.QueryRowContext(ctx, deleteUser)
var i User
err := row.Scan(
&i.ID,
&i.CreatedAt,
&i.UpdatedAt,
&i.Email,
&i.HashedPassword,
2024-10-26 15:03:14 +02:00
&i.IsChirpyRed,
)
return i, err
}
const getUserByEmail = `-- name: GetUserByEmail :one
2024-10-26 15:03:14 +02:00
SELECT id, created_at, updated_at, email, hashed_password, is_chirpy_red FROM users
WHERE users.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,
2024-10-26 15:03:14 +02:00
&i.IsChirpyRed,
2024-10-23 22:16:51 +02:00
)
return i, err
}
2024-10-26 15:03:14 +02:00
const updateUserCredentials = `-- name: UpdateUserCredentials :one
UPDATE users
SET email = $2,
hashed_password = $3,
updated_at = NOW()
WHERE users.id = $1
RETURNING id, created_at, updated_at, email, is_chirpy_red
`
type UpdateUserCredentialsParams struct {
ID uuid.UUID
Email string
HashedPassword string
}
type UpdateUserCredentialsRow struct {
ID uuid.UUID
CreatedAt time.Time
UpdatedAt time.Time
Email string
IsChirpyRed bool
}
func (q *Queries) UpdateUserCredentials(ctx context.Context, arg UpdateUserCredentialsParams) (UpdateUserCredentialsRow, error) {
row := q.db.QueryRowContext(ctx, updateUserCredentials, arg.ID, arg.Email, arg.HashedPassword)
var i UpdateUserCredentialsRow
err := row.Scan(
&i.ID,
&i.CreatedAt,
&i.UpdatedAt,
&i.Email,
&i.IsChirpyRed,
)
return i, err
}
2024-10-26 15:03:14 +02:00
const upgradeUser = `-- name: UpgradeUser :exec
UPDATE users
SET is_chirpy_red = true
WHERE id = $1
`
func (q *Queries) UpgradeUser(ctx context.Context, id uuid.UUID) error {
_, err := q.db.ExecContext(ctx, upgradeUser, id)
return err
}