166 lines
4.4 KiB
Go
166 lines
4.4 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: users.sql
|
|
|
|
package repository
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const createUser = `-- name: CreateUser :one
|
|
INSERT INTO users (id, email, password_hash, timezone)
|
|
VALUES ($1, $2, $3, $4)
|
|
RETURNING id, email, password_hash, timezone, is_active, created_at, updated_at
|
|
`
|
|
|
|
type CreateUserParams struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
Email string `json:"email"`
|
|
PasswordHash string `json:"password_hash"`
|
|
Timezone string `json:"timezone"`
|
|
}
|
|
|
|
type CreateUserRow struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
Email string `json:"email"`
|
|
PasswordHash string `json:"password_hash"`
|
|
Timezone string `json:"timezone"`
|
|
IsActive bool `json:"is_active"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
}
|
|
|
|
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (CreateUserRow, error) {
|
|
row := q.db.QueryRow(ctx, createUser,
|
|
arg.ID,
|
|
arg.Email,
|
|
arg.PasswordHash,
|
|
arg.Timezone,
|
|
)
|
|
var i CreateUserRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Email,
|
|
&i.PasswordHash,
|
|
&i.Timezone,
|
|
&i.IsActive,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getUserByEmail = `-- name: GetUserByEmail :one
|
|
SELECT id, email, password_hash, timezone, is_active, created_at, updated_at
|
|
FROM users
|
|
WHERE email = $1 AND deleted_at IS NULL
|
|
`
|
|
|
|
type GetUserByEmailRow struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
Email string `json:"email"`
|
|
PasswordHash string `json:"password_hash"`
|
|
Timezone string `json:"timezone"`
|
|
IsActive bool `json:"is_active"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
}
|
|
|
|
func (q *Queries) GetUserByEmail(ctx context.Context, email string) (GetUserByEmailRow, error) {
|
|
row := q.db.QueryRow(ctx, getUserByEmail, email)
|
|
var i GetUserByEmailRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Email,
|
|
&i.PasswordHash,
|
|
&i.Timezone,
|
|
&i.IsActive,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getUserByID = `-- name: GetUserByID :one
|
|
SELECT id, email, password_hash, timezone, is_active, created_at, updated_at
|
|
FROM users
|
|
WHERE id = $1 AND deleted_at IS NULL
|
|
`
|
|
|
|
type GetUserByIDRow struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
Email string `json:"email"`
|
|
PasswordHash string `json:"password_hash"`
|
|
Timezone string `json:"timezone"`
|
|
IsActive bool `json:"is_active"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
}
|
|
|
|
func (q *Queries) GetUserByID(ctx context.Context, id pgtype.UUID) (GetUserByIDRow, error) {
|
|
row := q.db.QueryRow(ctx, getUserByID, id)
|
|
var i GetUserByIDRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Email,
|
|
&i.PasswordHash,
|
|
&i.Timezone,
|
|
&i.IsActive,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const softDeleteUser = `-- name: SoftDeleteUser :exec
|
|
UPDATE users SET deleted_at = now(), is_active = false, updated_at = now()
|
|
WHERE id = $1 AND deleted_at IS NULL
|
|
`
|
|
|
|
func (q *Queries) SoftDeleteUser(ctx context.Context, id pgtype.UUID) error {
|
|
_, err := q.db.Exec(ctx, softDeleteUser, id)
|
|
return err
|
|
}
|
|
|
|
const updateUser = `-- name: UpdateUser :one
|
|
UPDATE users
|
|
SET timezone = COALESCE($1::TEXT, timezone),
|
|
updated_at = now()
|
|
WHERE id = $2 AND deleted_at IS NULL
|
|
RETURNING id, email, password_hash, timezone, is_active, created_at, updated_at
|
|
`
|
|
|
|
type UpdateUserParams struct {
|
|
Timezone pgtype.Text `json:"timezone"`
|
|
ID pgtype.UUID `json:"id"`
|
|
}
|
|
|
|
type UpdateUserRow struct {
|
|
ID pgtype.UUID `json:"id"`
|
|
Email string `json:"email"`
|
|
PasswordHash string `json:"password_hash"`
|
|
Timezone string `json:"timezone"`
|
|
IsActive bool `json:"is_active"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
}
|
|
|
|
func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) (UpdateUserRow, error) {
|
|
row := q.db.QueryRow(ctx, updateUser, arg.Timezone, arg.ID)
|
|
var i UpdateUserRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Email,
|
|
&i.PasswordHash,
|
|
&i.Timezone,
|
|
&i.IsActive,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|