@@ -0,0 +1,190 @@ |
| 1 | +// Code generated by sqlc. DO NOT EDIT. |
| 2 | +// versions: |
| 3 | +// sqlc v1.31.1 |
| 4 | +// source: user_emails.sql |
| 5 | + |
| 6 | +package usersdb |
| 7 | + |
| 8 | +import ( |
| 9 | + "context" |
| 10 | +) |
| 11 | + |
| 12 | +const createUserEmail = `-- name: CreateUserEmail :one |
| 13 | + |
| 14 | +INSERT INTO user_emails (user_id, email, is_primary, verified, verification_token_hash, verification_sent_at) |
| 15 | +VALUES ($1, $2, $3, $4, $5, CASE WHEN $5::bytea IS NULL THEN NULL ELSE now() END) |
| 16 | +RETURNING id, user_id, email, is_primary, verified, verification_token_hash, |
| 17 | + verification_sent_at, verified_at, created_at |
| 18 | +` |
| 19 | + |
| 20 | +type CreateUserEmailParams struct { |
| 21 | + UserID int64 |
| 22 | + Email string |
| 23 | + IsPrimary bool |
| 24 | + Verified bool |
| 25 | + VerificationTokenHash []byte |
| 26 | +} |
| 27 | + |
| 28 | +// SPDX-License-Identifier: AGPL-3.0-or-later |
| 29 | +func (q *Queries) CreateUserEmail(ctx context.Context, db DBTX, arg CreateUserEmailParams) (UserEmail, error) { |
| 30 | + row := db.QueryRow(ctx, createUserEmail, |
| 31 | + arg.UserID, |
| 32 | + arg.Email, |
| 33 | + arg.IsPrimary, |
| 34 | + arg.Verified, |
| 35 | + arg.VerificationTokenHash, |
| 36 | + ) |
| 37 | + var i UserEmail |
| 38 | + err := row.Scan( |
| 39 | + &i.ID, |
| 40 | + &i.UserID, |
| 41 | + &i.Email, |
| 42 | + &i.IsPrimary, |
| 43 | + &i.Verified, |
| 44 | + &i.VerificationTokenHash, |
| 45 | + &i.VerificationSentAt, |
| 46 | + &i.VerifiedAt, |
| 47 | + &i.CreatedAt, |
| 48 | + ) |
| 49 | + return i, err |
| 50 | +} |
| 51 | + |
| 52 | +const getUserEmailByAddress = `-- name: GetUserEmailByAddress :one |
| 53 | +SELECT id, user_id, email, is_primary, verified, verification_token_hash, |
| 54 | + verification_sent_at, verified_at, created_at |
| 55 | +FROM user_emails |
| 56 | +WHERE email = $1 |
| 57 | +` |
| 58 | + |
| 59 | +func (q *Queries) GetUserEmailByAddress(ctx context.Context, db DBTX, email string) (UserEmail, error) { |
| 60 | + row := db.QueryRow(ctx, getUserEmailByAddress, email) |
| 61 | + var i UserEmail |
| 62 | + err := row.Scan( |
| 63 | + &i.ID, |
| 64 | + &i.UserID, |
| 65 | + &i.Email, |
| 66 | + &i.IsPrimary, |
| 67 | + &i.Verified, |
| 68 | + &i.VerificationTokenHash, |
| 69 | + &i.VerificationSentAt, |
| 70 | + &i.VerifiedAt, |
| 71 | + &i.CreatedAt, |
| 72 | + ) |
| 73 | + return i, err |
| 74 | +} |
| 75 | + |
| 76 | +const getUserEmailByID = `-- name: GetUserEmailByID :one |
| 77 | +SELECT id, user_id, email, is_primary, verified, verification_token_hash, |
| 78 | + verification_sent_at, verified_at, created_at |
| 79 | +FROM user_emails |
| 80 | +WHERE id = $1 |
| 81 | +` |
| 82 | + |
| 83 | +func (q *Queries) GetUserEmailByID(ctx context.Context, db DBTX, id int64) (UserEmail, error) { |
| 84 | + row := db.QueryRow(ctx, getUserEmailByID, id) |
| 85 | + var i UserEmail |
| 86 | + err := row.Scan( |
| 87 | + &i.ID, |
| 88 | + &i.UserID, |
| 89 | + &i.Email, |
| 90 | + &i.IsPrimary, |
| 91 | + &i.Verified, |
| 92 | + &i.VerificationTokenHash, |
| 93 | + &i.VerificationSentAt, |
| 94 | + &i.VerifiedAt, |
| 95 | + &i.CreatedAt, |
| 96 | + ) |
| 97 | + return i, err |
| 98 | +} |
| 99 | + |
| 100 | +const getUserEmailByVerificationHash = `-- name: GetUserEmailByVerificationHash :one |
| 101 | +SELECT id, user_id, email, is_primary, verified, verification_token_hash, |
| 102 | + verification_sent_at, verified_at, created_at |
| 103 | +FROM user_emails |
| 104 | +WHERE verification_token_hash = $1 |
| 105 | +` |
| 106 | + |
| 107 | +func (q *Queries) GetUserEmailByVerificationHash(ctx context.Context, db DBTX, verificationTokenHash []byte) (UserEmail, error) { |
| 108 | + row := db.QueryRow(ctx, getUserEmailByVerificationHash, verificationTokenHash) |
| 109 | + var i UserEmail |
| 110 | + err := row.Scan( |
| 111 | + &i.ID, |
| 112 | + &i.UserID, |
| 113 | + &i.Email, |
| 114 | + &i.IsPrimary, |
| 115 | + &i.Verified, |
| 116 | + &i.VerificationTokenHash, |
| 117 | + &i.VerificationSentAt, |
| 118 | + &i.VerifiedAt, |
| 119 | + &i.CreatedAt, |
| 120 | + ) |
| 121 | + return i, err |
| 122 | +} |
| 123 | + |
| 124 | +const listUserEmailsForUser = `-- name: ListUserEmailsForUser :many |
| 125 | +SELECT id, user_id, email, is_primary, verified, verification_token_hash, |
| 126 | + verification_sent_at, verified_at, created_at |
| 127 | +FROM user_emails |
| 128 | +WHERE user_id = $1 |
| 129 | +ORDER BY is_primary DESC, created_at |
| 130 | +` |
| 131 | + |
| 132 | +func (q *Queries) ListUserEmailsForUser(ctx context.Context, db DBTX, userID int64) ([]UserEmail, error) { |
| 133 | + rows, err := db.Query(ctx, listUserEmailsForUser, userID) |
| 134 | + if err != nil { |
| 135 | + return nil, err |
| 136 | + } |
| 137 | + defer rows.Close() |
| 138 | + items := []UserEmail{} |
| 139 | + for rows.Next() { |
| 140 | + var i UserEmail |
| 141 | + if err := rows.Scan( |
| 142 | + &i.ID, |
| 143 | + &i.UserID, |
| 144 | + &i.Email, |
| 145 | + &i.IsPrimary, |
| 146 | + &i.Verified, |
| 147 | + &i.VerificationTokenHash, |
| 148 | + &i.VerificationSentAt, |
| 149 | + &i.VerifiedAt, |
| 150 | + &i.CreatedAt, |
| 151 | + ); err != nil { |
| 152 | + return nil, err |
| 153 | + } |
| 154 | + items = append(items, i) |
| 155 | + } |
| 156 | + if err := rows.Err(); err != nil { |
| 157 | + return nil, err |
| 158 | + } |
| 159 | + return items, nil |
| 160 | +} |
| 161 | + |
| 162 | +const markUserEmailVerified = `-- name: MarkUserEmailVerified :exec |
| 163 | +UPDATE user_emails |
| 164 | +SET verified = true, |
| 165 | + verified_at = now(), |
| 166 | + verification_token_hash = NULL |
| 167 | +WHERE id = $1 |
| 168 | +` |
| 169 | + |
| 170 | +func (q *Queries) MarkUserEmailVerified(ctx context.Context, db DBTX, id int64) error { |
| 171 | + _, err := db.Exec(ctx, markUserEmailVerified, id) |
| 172 | + return err |
| 173 | +} |
| 174 | + |
| 175 | +const setVerificationToken = `-- name: SetVerificationToken :exec |
| 176 | +UPDATE user_emails |
| 177 | +SET verification_token_hash = $2, |
| 178 | + verification_sent_at = now() |
| 179 | +WHERE id = $1 |
| 180 | +` |
| 181 | + |
| 182 | +type SetVerificationTokenParams struct { |
| 183 | + ID int64 |
| 184 | + VerificationTokenHash []byte |
| 185 | +} |
| 186 | + |
| 187 | +func (q *Queries) SetVerificationToken(ctx context.Context, db DBTX, arg SetVerificationTokenParams) error { |
| 188 | + _, err := db.Exec(ctx, setVerificationToken, arg.ID, arg.VerificationTokenHash) |
| 189 | + return err |
| 190 | +} |