127 lines
3.4 KiB
Go
127 lines
3.4 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.25.0
|
|
// source: password_tokens.sql
|
|
|
|
package sqlc
|
|
|
|
import (
|
|
"context"
|
|
|
|
"git.grosinger.net/tgrosinger/saasitone/pkg/db"
|
|
)
|
|
|
|
const createPasswordToken = `-- name: CreatePasswordToken :one
|
|
INSERT INTO password_tokens (
|
|
hash, password_token_user
|
|
) VALUES (
|
|
?, ?
|
|
) RETURNING id, hash, created_at, password_token_user
|
|
`
|
|
|
|
type CreatePasswordTokenParams struct {
|
|
Hash string `db:"hash"`
|
|
PasswordTokenUser int `db:"password_token_user"`
|
|
}
|
|
|
|
func (q *Queries) CreatePasswordToken(ctx context.Context, arg CreatePasswordTokenParams) (PasswordToken, error) {
|
|
row := q.db.QueryRowContext(ctx, createPasswordToken, arg.Hash, arg.PasswordTokenUser)
|
|
var i PasswordToken
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Hash,
|
|
&i.CreatedAt,
|
|
&i.PasswordTokenUser,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deletePasswordTokens = `-- name: DeletePasswordTokens :exec
|
|
DELETE FROM password_tokens
|
|
WHERE password_token_user = ?
|
|
`
|
|
|
|
func (q *Queries) DeletePasswordTokens(ctx context.Context, passwordTokenUser int) error {
|
|
_, err := q.db.ExecContext(ctx, deletePasswordTokens, passwordTokenUser)
|
|
return err
|
|
}
|
|
|
|
const getAllPasswordTokensForUser = `-- name: GetAllPasswordTokensForUser :many
|
|
SELECT id, hash, created_at, password_token_user FROM password_tokens
|
|
WHERE password_token_user = ?
|
|
`
|
|
|
|
// GetAllPasswordTokensForUser retrieves all password tokens without checking expiration.
|
|
func (q *Queries) GetAllPasswordTokensForUser(ctx context.Context, passwordTokenUser int) ([]PasswordToken, error) {
|
|
rows, err := q.db.QueryContext(ctx, getAllPasswordTokensForUser, passwordTokenUser)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []PasswordToken
|
|
for rows.Next() {
|
|
var i PasswordToken
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Hash,
|
|
&i.CreatedAt,
|
|
&i.PasswordTokenUser,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const getValidPasswordToken = `-- name: GetValidPasswordToken :one
|
|
SELECT id, hash, created_at, password_token_user FROM password_tokens
|
|
WHERE
|
|
id = ?
|
|
AND password_token_user = ?
|
|
AND datetime(created_at) > datetime(?)
|
|
LIMIT 1
|
|
`
|
|
|
|
type GetValidPasswordTokenParams struct {
|
|
ID int `db:"id"`
|
|
PasswordTokenUser int `db:"password_token_user"`
|
|
Datetime interface{} `db:"datetime"`
|
|
}
|
|
|
|
// GetValidPasswordToken returns only valid password tokens for the provided
|
|
// user, and only if the created_at time is greater than the provided time.
|
|
func (q *Queries) GetValidPasswordToken(ctx context.Context, arg GetValidPasswordTokenParams) (PasswordToken, error) {
|
|
row := q.db.QueryRowContext(ctx, getValidPasswordToken, arg.ID, arg.PasswordTokenUser, arg.Datetime)
|
|
var i PasswordToken
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Hash,
|
|
&i.CreatedAt,
|
|
&i.PasswordTokenUser,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const updatePasswordTokenCreatedAt = `-- name: UpdatePasswordTokenCreatedAt :exec
|
|
UPDATE password_tokens
|
|
SET created_at = ?
|
|
WHERE id = ?
|
|
`
|
|
|
|
type UpdatePasswordTokenCreatedAtParams struct {
|
|
CreatedAt db.Time `db:"created_at"`
|
|
ID int `db:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdatePasswordTokenCreatedAt(ctx context.Context, arg UpdatePasswordTokenCreatedAtParams) error {
|
|
_, err := q.db.ExecContext(ctx, updatePasswordTokenCreatedAt, arg.CreatedAt, arg.ID)
|
|
return err
|
|
}
|