Go · 1529 bytes Raw Blame History
1 // Code generated by sqlc. DO NOT EDIT.
2 // versions:
3 // sqlc v1.31.1
4 // source: username_redirects.sql
5
6 package usersdb
7
8 import (
9 "context"
10
11 "github.com/jackc/pgx/v5/pgtype"
12 )
13
14 const insertUsernameRedirect = `-- name: InsertUsernameRedirect :exec
15 INSERT INTO username_redirects (old_username, user_id) VALUES ($1, $2)
16 `
17
18 type InsertUsernameRedirectParams struct {
19 OldUsername string
20 UserID int64
21 }
22
23 // Used by the S10 username-change flow to record an old name. The
24 // redirect itself doubles as a 30-day reservation (the row stays for at
25 // least that long).
26 func (q *Queries) InsertUsernameRedirect(ctx context.Context, db DBTX, arg InsertUsernameRedirectParams) error {
27 _, err := db.Exec(ctx, insertUsernameRedirect, arg.OldUsername, arg.UserID)
28 return err
29 }
30
31 const lookupUsernameRedirect = `-- name: LookupUsernameRedirect :one
32
33 SELECT u.username, r.changed_at
34 FROM username_redirects r
35 JOIN users u ON u.id = r.user_id
36 WHERE r.old_username = $1 AND u.deleted_at IS NULL
37 `
38
39 type LookupUsernameRedirectRow struct {
40 Username string
41 ChangedAt pgtype.Timestamptz
42 }
43
44 // SPDX-License-Identifier: AGPL-3.0-or-later
45 // Resolve an old username to the current username via the user_id FK.
46 // Returns ErrNoRows when no redirect exists.
47 func (q *Queries) LookupUsernameRedirect(ctx context.Context, db DBTX, oldUsername string) (LookupUsernameRedirectRow, error) {
48 row := db.QueryRow(ctx, lookupUsernameRedirect, oldUsername)
49 var i LookupUsernameRedirectRow
50 err := row.Scan(&i.Username, &i.ChangedAt)
51 return i, err
52 }
53