118 lines
2.8 KiB
Go
118 lines
2.8 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: otp.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const CreateOtp = `-- name: CreateOtp :exec
|
|
INSERT INTO otps (user_name, sent_to, medium, otp_for, otp, used, created_at, expires_at)
|
|
VALUES ($1, $2, $3, $4, $5, FALSE, $6, $7)
|
|
`
|
|
|
|
type CreateOtpParams struct {
|
|
UserName string `json:"user_name"`
|
|
SentTo string `json:"sent_to"`
|
|
Medium string `json:"medium"`
|
|
OtpFor string `json:"otp_for"`
|
|
Otp string `json:"otp"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
ExpiresAt pgtype.Timestamptz `json:"expires_at"`
|
|
}
|
|
|
|
func (q *Queries) CreateOtp(ctx context.Context, arg CreateOtpParams) error {
|
|
_, err := q.db.Exec(ctx, CreateOtp,
|
|
arg.UserName,
|
|
arg.SentTo,
|
|
arg.Medium,
|
|
arg.OtpFor,
|
|
arg.Otp,
|
|
arg.CreatedAt,
|
|
arg.ExpiresAt,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const GetOtp = `-- name: GetOtp :one
|
|
SELECT id, user_name, sent_to, medium, otp_for, otp, used, used_at, created_at, expires_at
|
|
FROM otps
|
|
WHERE user_name = $1
|
|
ORDER BY created_at DESC LIMIT 1
|
|
`
|
|
|
|
type GetOtpRow struct {
|
|
ID int64 `json:"id"`
|
|
UserName string `json:"user_name"`
|
|
SentTo string `json:"sent_to"`
|
|
Medium string `json:"medium"`
|
|
OtpFor string `json:"otp_for"`
|
|
Otp string `json:"otp"`
|
|
Used bool `json:"used"`
|
|
UsedAt pgtype.Timestamptz `json:"used_at"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
ExpiresAt pgtype.Timestamptz `json:"expires_at"`
|
|
}
|
|
|
|
func (q *Queries) GetOtp(ctx context.Context, userName string) (GetOtpRow, error) {
|
|
row := q.db.QueryRow(ctx, GetOtp, userName)
|
|
var i GetOtpRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserName,
|
|
&i.SentTo,
|
|
&i.Medium,
|
|
&i.OtpFor,
|
|
&i.Otp,
|
|
&i.Used,
|
|
&i.UsedAt,
|
|
&i.CreatedAt,
|
|
&i.ExpiresAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const MarkOtpAsUsed = `-- name: MarkOtpAsUsed :exec
|
|
UPDATE otps
|
|
SET used = TRUE, used_at = $2
|
|
WHERE id = $1
|
|
`
|
|
|
|
type MarkOtpAsUsedParams struct {
|
|
ID int64 `json:"id"`
|
|
UsedAt pgtype.Timestamptz `json:"used_at"`
|
|
}
|
|
|
|
func (q *Queries) MarkOtpAsUsed(ctx context.Context, arg MarkOtpAsUsedParams) error {
|
|
_, err := q.db.Exec(ctx, MarkOtpAsUsed, arg.ID, arg.UsedAt)
|
|
return err
|
|
}
|
|
|
|
const UpdateExpiredOtp = `-- name: UpdateExpiredOtp :exec
|
|
UPDATE otps
|
|
SET
|
|
otp = $2,
|
|
used = FALSE,
|
|
used_at = NULL,
|
|
expires_at = $3
|
|
WHERE
|
|
user_name = $1
|
|
AND expires_at <= NOW()
|
|
`
|
|
|
|
type UpdateExpiredOtpParams struct {
|
|
UserName string `json:"user_name"`
|
|
Otp string `json:"otp"`
|
|
ExpiresAt pgtype.Timestamptz `json:"expires_at"`
|
|
}
|
|
|
|
func (q *Queries) UpdateExpiredOtp(ctx context.Context, arg UpdateExpiredOtpParams) error {
|
|
_, err := q.db.Exec(ctx, UpdateExpiredOtp, arg.UserName, arg.Otp, arg.ExpiresAt)
|
|
return err
|
|
}
|