| 1 | // Code generated by sqlc. DO NOT EDIT. |
| 2 | // versions: |
| 3 | // sqlc v1.31.1 |
| 4 | // source: email_verifications.sql |
| 5 | |
| 6 | package usersdb |
| 7 | |
| 8 | import ( |
| 9 | "context" |
| 10 | |
| 11 | "github.com/jackc/pgx/v5/pgtype" |
| 12 | ) |
| 13 | |
| 14 | const consumeEmailVerification = `-- name: ConsumeEmailVerification :exec |
| 15 | UPDATE email_verifications |
| 16 | SET used_at = now() |
| 17 | WHERE id = $1 AND used_at IS NULL |
| 18 | ` |
| 19 | |
| 20 | func (q *Queries) ConsumeEmailVerification(ctx context.Context, db DBTX, id int64) error { |
| 21 | _, err := db.Exec(ctx, consumeEmailVerification, id) |
| 22 | return err |
| 23 | } |
| 24 | |
| 25 | const createEmailVerification = `-- name: CreateEmailVerification :one |
| 26 | |
| 27 | INSERT INTO email_verifications (user_email_id, token_hash, expires_at) |
| 28 | VALUES ($1, $2, $3) |
| 29 | RETURNING id, user_email_id, token_hash, expires_at, used_at, created_at |
| 30 | ` |
| 31 | |
| 32 | type CreateEmailVerificationParams struct { |
| 33 | UserEmailID int64 |
| 34 | TokenHash []byte |
| 35 | ExpiresAt pgtype.Timestamptz |
| 36 | } |
| 37 | |
| 38 | // SPDX-License-Identifier: AGPL-3.0-or-later |
| 39 | func (q *Queries) CreateEmailVerification(ctx context.Context, db DBTX, arg CreateEmailVerificationParams) (EmailVerification, error) { |
| 40 | row := db.QueryRow(ctx, createEmailVerification, arg.UserEmailID, arg.TokenHash, arg.ExpiresAt) |
| 41 | var i EmailVerification |
| 42 | err := row.Scan( |
| 43 | &i.ID, |
| 44 | &i.UserEmailID, |
| 45 | &i.TokenHash, |
| 46 | &i.ExpiresAt, |
| 47 | &i.UsedAt, |
| 48 | &i.CreatedAt, |
| 49 | ) |
| 50 | return i, err |
| 51 | } |
| 52 | |
| 53 | const deleteExpiredEmailVerifications = `-- name: DeleteExpiredEmailVerifications :exec |
| 54 | DELETE FROM email_verifications WHERE expires_at < now() |
| 55 | ` |
| 56 | |
| 57 | func (q *Queries) DeleteExpiredEmailVerifications(ctx context.Context, db DBTX) error { |
| 58 | _, err := db.Exec(ctx, deleteExpiredEmailVerifications) |
| 59 | return err |
| 60 | } |
| 61 | |
| 62 | const getEmailVerificationByTokenHash = `-- name: GetEmailVerificationByTokenHash :one |
| 63 | SELECT id, user_email_id, token_hash, expires_at, used_at, created_at |
| 64 | FROM email_verifications |
| 65 | WHERE token_hash = $1 |
| 66 | ` |
| 67 | |
| 68 | func (q *Queries) GetEmailVerificationByTokenHash(ctx context.Context, db DBTX, tokenHash []byte) (EmailVerification, error) { |
| 69 | row := db.QueryRow(ctx, getEmailVerificationByTokenHash, tokenHash) |
| 70 | var i EmailVerification |
| 71 | err := row.Scan( |
| 72 | &i.ID, |
| 73 | &i.UserEmailID, |
| 74 | &i.TokenHash, |
| 75 | &i.ExpiresAt, |
| 76 | &i.UsedAt, |
| 77 | &i.CreatedAt, |
| 78 | ) |
| 79 | return i, err |
| 80 | } |
| 81 |