Files
easywish/backend/internal/database/query.sql.go
Nikolai Papin 669349e020 chore: remove direct avatar upload endpoint (POST /profile/avatar);
feat: add endpoints for presigned upload URLs (GET /upload/avatar, GET /upload/image);
refactor: replace ProfileDto with NewProfileDto in update profile endpoint;
feat: implement S3 integration for avatar management;
fix: update database queries to handle new avatar upload flow;
chore: add new dependencies for S3 handling (golang.org/x/time);
refactor: rename UploadService to S3Service;
refactor: change return type for func LocalizeS3Url(originalURL string) (*url.URL, error);
feat: add custom validator for upload_id
2025-08-01 04:34:06 +03:00

1136 lines
29 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.29.0
// source: query.sql
package database
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const checkUserRegistrationAvailability = `-- name: CheckUserRegistrationAvailability :one
SELECT
COUNT(CASE WHEN users.username = $1::text THEN 1 END) > 0 AS username_busy,
COUNT(CASE WHEN linfo.email = $2::text THEN 1 END) > 0 AS email_busy
FROM users
JOIN login_informations AS linfo ON linfo.user_id = users.id
WHERE
(
users.username = $1::text OR
linfo.email = $2::text
)
AND
(
users.verified IS TRUE OR
NOT EXISTS (
SELECT 1
FROM confirmation_codes AS codes
WHERE codes.user_id = users.id
AND codes.code_type = 0
AND codes.deleted IS FALSE
AND codes.expires_at > CURRENT_TIMESTAMP
)
)
`
type CheckUserRegistrationAvailabilityParams struct {
Username string
Email string
}
type CheckUserRegistrationAvailabilityRow struct {
UsernameBusy bool
EmailBusy bool
}
func (q *Queries) CheckUserRegistrationAvailability(ctx context.Context, arg CheckUserRegistrationAvailabilityParams) (CheckUserRegistrationAvailabilityRow, error) {
row := q.db.QueryRow(ctx, checkUserRegistrationAvailability, arg.Username, arg.Email)
var i CheckUserRegistrationAvailabilityRow
err := row.Scan(&i.UsernameBusy, &i.EmailBusy)
return i, err
}
const createBannedUser = `-- name: CreateBannedUser :one
INSERT INTO banned_users(user_id, expires_at, reason, banned_by)
VALUES ( $1, $2, $3, $4) RETURNING id, user_id, date, reason, expires_at, banned_by, pardoned, pardoned_by
`
type CreateBannedUserParams struct {
UserID int64
ExpiresAt pgtype.Timestamp
Reason *string
BannedBy *string
}
func (q *Queries) CreateBannedUser(ctx context.Context, arg CreateBannedUserParams) (BannedUser, error) {
row := q.db.QueryRow(ctx, createBannedUser,
arg.UserID,
arg.ExpiresAt,
arg.Reason,
arg.BannedBy,
)
var i BannedUser
err := row.Scan(
&i.ID,
&i.UserID,
&i.Date,
&i.Reason,
&i.ExpiresAt,
&i.BannedBy,
&i.Pardoned,
&i.PardonedBy,
)
return i, err
}
const createConfirmationCode = `-- name: CreateConfirmationCode :one
INSERT INTO confirmation_codes(user_id, code_type, code_hash)
VALUES ($1, $2, $3) RETURNING id, user_id, code_type, code_hash, expires_at, used, deleted
`
type CreateConfirmationCodeParams struct {
UserID int64
CodeType int32
CodeHash string
}
func (q *Queries) CreateConfirmationCode(ctx context.Context, arg CreateConfirmationCodeParams) (ConfirmationCode, error) {
row := q.db.QueryRow(ctx, createConfirmationCode, arg.UserID, arg.CodeType, arg.CodeHash)
var i ConfirmationCode
err := row.Scan(
&i.ID,
&i.UserID,
&i.CodeType,
&i.CodeHash,
&i.ExpiresAt,
&i.Used,
&i.Deleted,
)
return i, err
}
const createLoginInformation = `-- name: CreateLoginInformation :one
INSERT INTO login_informations(user_id, email, password_hash)
VALUES ( $1, $2, $3::text ) RETURNING id, user_id, email, password_hash, totp_encrypted, email_2fa_enabled, password_change_date
`
type CreateLoginInformationParams struct {
UserID int64
Email *string
PasswordHash string
}
func (q *Queries) CreateLoginInformation(ctx context.Context, arg CreateLoginInformationParams) (LoginInformation, error) {
row := q.db.QueryRow(ctx, createLoginInformation, arg.UserID, arg.Email, arg.PasswordHash)
var i LoginInformation
err := row.Scan(
&i.ID,
&i.UserID,
&i.Email,
&i.PasswordHash,
&i.TotpEncrypted,
&i.Email2faEnabled,
&i.PasswordChangeDate,
)
return i, err
}
const createProfile = `-- name: CreateProfile :one
INSERT INTO profiles(user_id, name, bio, birthday, avatar_url, color, color_grad)
VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING id, user_id, name, bio, avatar_url, birthday, color, color_grad
`
type CreateProfileParams struct {
UserID int64
Name string
Bio string
Birthday pgtype.Timestamp
AvatarUrl string
Color string
ColorGrad string
}
func (q *Queries) CreateProfile(ctx context.Context, arg CreateProfileParams) (Profile, error) {
row := q.db.QueryRow(ctx, createProfile,
arg.UserID,
arg.Name,
arg.Bio,
arg.Birthday,
arg.AvatarUrl,
arg.Color,
arg.ColorGrad,
)
var i Profile
err := row.Scan(
&i.ID,
&i.UserID,
&i.Name,
&i.Bio,
&i.AvatarUrl,
&i.Birthday,
&i.Color,
&i.ColorGrad,
)
return i, err
}
const createProfileSettings = `-- name: CreateProfileSettings :one
INSERT INTO profile_settings(profile_id)
VALUES ($1) RETURNING id, profile_id, hide_fulfilled, hide_profile_details, hide_for_unauthenticated, hide_birthday, hide_dates, captcha, followers_only_interaction
`
func (q *Queries) CreateProfileSettings(ctx context.Context, profileID int64) (ProfileSetting, error) {
row := q.db.QueryRow(ctx, createProfileSettings, profileID)
var i ProfileSetting
err := row.Scan(
&i.ID,
&i.ProfileID,
&i.HideFulfilled,
&i.HideProfileDetails,
&i.HideForUnauthenticated,
&i.HideBirthday,
&i.HideDates,
&i.Captcha,
&i.FollowersOnlyInteraction,
)
return i, err
}
const createSession = `-- name: CreateSession :one
INSERT INTO sessions(user_id, name, platform, latest_ip)
VALUES ($1, $2, $3, $4) RETURNING id, user_id, guid, name, platform, latest_ip, login_time, last_refresh_exp_time, last_seen_date, terminated
`
type CreateSessionParams struct {
UserID int64
Name *string
Platform *string
LatestIp *string
}
func (q *Queries) CreateSession(ctx context.Context, arg CreateSessionParams) (Session, error) {
row := q.db.QueryRow(ctx, createSession,
arg.UserID,
arg.Name,
arg.Platform,
arg.LatestIp,
)
var i Session
err := row.Scan(
&i.ID,
&i.UserID,
&i.Guid,
&i.Name,
&i.Platform,
&i.LatestIp,
&i.LoginTime,
&i.LastRefreshExpTime,
&i.LastSeenDate,
&i.Terminated,
)
return i, err
}
const createUser = `-- name: CreateUser :one
INSERT INTO users(username, verified)
VALUES ($1, false) RETURNING id, username, verified, registration_date, role, deleted
`
func (q *Queries) CreateUser(ctx context.Context, username string) (User, error) {
row := q.db.QueryRow(ctx, createUser, username)
var i User
err := row.Scan(
&i.ID,
&i.Username,
&i.Verified,
&i.RegistrationDate,
&i.Role,
&i.Deleted,
)
return i, err
}
const deleteUnverifiedAccountsHavingUsernameOrEmail = `-- name: DeleteUnverifiedAccountsHavingUsernameOrEmail :one
WITH deleted_rows AS (
DELETE FROM users
WHERE
(username = $1::text OR
EXISTS (
SELECT 1
FROM login_informations AS linfo
WHERE linfo.user_id = users.id
AND linfo.email = $2::text
))
AND verified IS FALSE
RETURNING id, username, verified, registration_date, role, deleted
)
SELECT COUNT(*) AS deleted_count FROM deleted_rows
`
type DeleteUnverifiedAccountsHavingUsernameOrEmailParams struct {
Username string
Email string
}
func (q *Queries) DeleteUnverifiedAccountsHavingUsernameOrEmail(ctx context.Context, arg DeleteUnverifiedAccountsHavingUsernameOrEmailParams) (int64, error) {
row := q.db.QueryRow(ctx, deleteUnverifiedAccountsHavingUsernameOrEmail, arg.Username, arg.Email)
var deleted_count int64
err := row.Scan(&deleted_count)
return deleted_count, err
}
const deleteUser = `-- name: DeleteUser :exec
DELETE FROM users
WHERE id = $1
`
func (q *Queries) DeleteUser(ctx context.Context, id int64) error {
_, err := q.db.Exec(ctx, deleteUser, id)
return err
}
const deleteUserByUsername = `-- name: DeleteUserByUsername :exec
DELETE FROM users
WHERE username = $1
`
func (q *Queries) DeleteUserByUsername(ctx context.Context, username string) error {
_, err := q.db.Exec(ctx, deleteUserByUsername, username)
return err
}
const getLoginInformationByUsername = `-- name: GetLoginInformationByUsername :one
SELECT login_informations.id, login_informations.user_id, login_informations.email, login_informations.password_hash, login_informations.totp_encrypted, login_informations.email_2fa_enabled, login_informations.password_change_date FROM login_informations
JOIN users ON users.id = login_informations.user_id
WHERE users.username = $1
`
func (q *Queries) GetLoginInformationByUsername(ctx context.Context, username string) (LoginInformation, error) {
row := q.db.QueryRow(ctx, getLoginInformationByUsername, username)
var i LoginInformation
err := row.Scan(
&i.ID,
&i.UserID,
&i.Email,
&i.PasswordHash,
&i.TotpEncrypted,
&i.Email2faEnabled,
&i.PasswordChangeDate,
)
return i, err
}
const getProfileByUsername = `-- name: GetProfileByUsername :one
SELECT profiles.id, profiles.user_id, profiles.name, profiles.bio, profiles.avatar_url, profiles.birthday, profiles.color, profiles.color_grad FROM profiles
JOIN users ON users.id = profiles.user_id
WHERE users.username = $1
`
func (q *Queries) GetProfileByUsername(ctx context.Context, username string) (Profile, error) {
row := q.db.QueryRow(ctx, getProfileByUsername, username)
var i Profile
err := row.Scan(
&i.ID,
&i.UserID,
&i.Name,
&i.Bio,
&i.AvatarUrl,
&i.Birthday,
&i.Color,
&i.ColorGrad,
)
return i, err
}
const getProfileByUsernameRestricted = `-- name: GetProfileByUsernameRestricted :one
SELECT
users.username,
profiles.name,
CASE
WHEN profile_settings.hide_birthday OR profile_settings.hide_profile_details THEN NULL
ELSE profiles.birthday
END AS birthday,
CASE
WHEN profile_settings.hide_profile_details THEN NULL
ELSE profiles.bio
END AS bio,
CASE
WHEN profile_settings.hide_profile_details THEN NULL
ELSE profiles.avatar_url
END AS avatar_url,
profiles.color,
profiles.color_grad,
profile_settings.hide_profile_details
FROM profiles
JOIN users ON users.id = profiles.user_id
JOIN profile_settings ON profiles.id = profile_settings.profile_id
WHERE users.username = $1 AND ($2 IS FALSE OR profile_settings.hide_for_unauthenticated IS FALSE)
`
type GetProfileByUsernameRestrictedParams struct {
Username string
Column2 *bool
}
type GetProfileByUsernameRestrictedRow struct {
Username string
Name string
Birthday pgtype.Timestamp
Bio *string
AvatarUrl *string
Color string
ColorGrad string
HideProfileDetails bool
}
func (q *Queries) GetProfileByUsernameRestricted(ctx context.Context, arg GetProfileByUsernameRestrictedParams) (GetProfileByUsernameRestrictedRow, error) {
row := q.db.QueryRow(ctx, getProfileByUsernameRestricted, arg.Username, arg.Column2)
var i GetProfileByUsernameRestrictedRow
err := row.Scan(
&i.Username,
&i.Name,
&i.Birthday,
&i.Bio,
&i.AvatarUrl,
&i.Color,
&i.ColorGrad,
&i.HideProfileDetails,
)
return i, err
}
const getProfileSettingsByUsername = `-- name: GetProfileSettingsByUsername :one
SELECT profile_settings.id, profile_settings.profile_id, profile_settings.hide_fulfilled, profile_settings.hide_profile_details, profile_settings.hide_for_unauthenticated, profile_settings.hide_birthday, profile_settings.hide_dates, profile_settings.captcha, profile_settings.followers_only_interaction FROM profile_settings
JOIN profiles ON profiles.id = profile_settings.profile_id
JOIN users ON users.id = profiles.user_id
WHERE users.username = $1
`
func (q *Queries) GetProfileSettingsByUsername(ctx context.Context, username string) (ProfileSetting, error) {
row := q.db.QueryRow(ctx, getProfileSettingsByUsername, username)
var i ProfileSetting
err := row.Scan(
&i.ID,
&i.ProfileID,
&i.HideFulfilled,
&i.HideProfileDetails,
&i.HideForUnauthenticated,
&i.HideBirthday,
&i.HideDates,
&i.Captcha,
&i.FollowersOnlyInteraction,
)
return i, err
}
const getProfilesRestricted = `-- name: GetProfilesRestricted :many
SELECT
users.username,
profiles.name,
CASE
WHEN profile_settings.hide_profile_details THEN NULL
ELSE profiles.avatar_url
END AS avatar_url,
profiles.color,
profiles.color_grad,
profile_settings.hide_profile_details
FROM profiles
JOIN users ON users.id = profiles.user_id
JOIN profile_settings ON profile_settings.profile_id = profiles.id
WHERE users.deleted IS FALSE AND ($2 IS FALSE OR profile_settings.hide_for_unauthenticated IS FALSE)
ORDER BY profiles.id DESC
LIMIT 20 OFFSET 20 * $1
`
type GetProfilesRestrictedParams struct {
Column1 *int32
Column2 *bool
}
type GetProfilesRestrictedRow struct {
Username string
Name string
AvatarUrl *string
Color string
ColorGrad string
HideProfileDetails bool
}
func (q *Queries) GetProfilesRestricted(ctx context.Context, arg GetProfilesRestrictedParams) ([]GetProfilesRestrictedRow, error) {
rows, err := q.db.Query(ctx, getProfilesRestricted, arg.Column1, arg.Column2)
if err != nil {
return nil, err
}
defer rows.Close()
var items []GetProfilesRestrictedRow
for rows.Next() {
var i GetProfilesRestrictedRow
if err := rows.Scan(
&i.Username,
&i.Name,
&i.AvatarUrl,
&i.Color,
&i.ColorGrad,
&i.HideProfileDetails,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getSessionByGuid = `-- name: GetSessionByGuid :one
SELECT id, user_id, guid, name, platform, latest_ip, login_time, last_refresh_exp_time, last_seen_date, terminated FROM sessions
WHERE guid = ($1::text)::uuid
`
func (q *Queries) GetSessionByGuid(ctx context.Context, guid string) (Session, error) {
row := q.db.QueryRow(ctx, getSessionByGuid, guid)
var i Session
err := row.Scan(
&i.ID,
&i.UserID,
&i.Guid,
&i.Name,
&i.Platform,
&i.LatestIp,
&i.LoginTime,
&i.LastRefreshExpTime,
&i.LastSeenDate,
&i.Terminated,
)
return i, err
}
const getUnexpiredTerminatedSessionsGuidsPaginated = `-- name: GetUnexpiredTerminatedSessionsGuidsPaginated :many
SELECT guid FROM sessions
WHERE
terminated IS TRUE AND
last_refresh_exp_time > CURRENT_TIMESTAMP
LIMIT $1::integer
OFFSET $2
`
type GetUnexpiredTerminatedSessionsGuidsPaginatedParams struct {
BatchSize int32
Offset int64
}
func (q *Queries) GetUnexpiredTerminatedSessionsGuidsPaginated(ctx context.Context, arg GetUnexpiredTerminatedSessionsGuidsPaginatedParams) ([]pgtype.UUID, error) {
rows, err := q.db.Query(ctx, getUnexpiredTerminatedSessionsGuidsPaginated, arg.BatchSize, arg.Offset)
if err != nil {
return nil, err
}
defer rows.Close()
var items []pgtype.UUID
for rows.Next() {
var guid pgtype.UUID
if err := rows.Scan(&guid); err != nil {
return nil, err
}
items = append(items, guid)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getUser = `-- name: GetUser :one
SELECT id, username, verified, registration_date, role, deleted FROM users
WHERE id = $1
`
func (q *Queries) GetUser(ctx context.Context, id int64) (User, error) {
row := q.db.QueryRow(ctx, getUser, id)
var i User
err := row.Scan(
&i.ID,
&i.Username,
&i.Verified,
&i.RegistrationDate,
&i.Role,
&i.Deleted,
)
return i, err
}
const getUserBans = `-- name: GetUserBans :many
SELECT id, user_id, date, reason, expires_at, banned_by, pardoned, pardoned_by FROM banned_users
WHERE user_id = $1
`
func (q *Queries) GetUserBans(ctx context.Context, userID int64) ([]BannedUser, error) {
rows, err := q.db.Query(ctx, getUserBans, userID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []BannedUser
for rows.Next() {
var i BannedUser
if err := rows.Scan(
&i.ID,
&i.UserID,
&i.Date,
&i.Reason,
&i.ExpiresAt,
&i.BannedBy,
&i.Pardoned,
&i.PardonedBy,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getUserBansByUsername = `-- name: GetUserBansByUsername :many
SELECT banned_users.id, banned_users.user_id, banned_users.date, banned_users.reason, banned_users.expires_at, banned_users.banned_by, banned_users.pardoned, banned_users.pardoned_by FROM banned_users
JOIN users ON users.id = banned_users.user_id
WHERE users.username = $1
`
func (q *Queries) GetUserBansByUsername(ctx context.Context, username string) ([]BannedUser, error) {
rows, err := q.db.Query(ctx, getUserBansByUsername, username)
if err != nil {
return nil, err
}
defer rows.Close()
var items []BannedUser
for rows.Next() {
var i BannedUser
if err := rows.Scan(
&i.ID,
&i.UserID,
&i.Date,
&i.Reason,
&i.ExpiresAt,
&i.BannedBy,
&i.Pardoned,
&i.PardonedBy,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getUserByEmail = `-- name: GetUserByEmail :one
SELECT users.id, users.username, users.verified, users.registration_date, users.role, users.deleted FROM users
JOIN login_informations linfo ON linfo.user_id = users.id
WHERE linfo.email = $1::text
`
func (q *Queries) GetUserByEmail(ctx context.Context, email string) (User, error) {
row := q.db.QueryRow(ctx, getUserByEmail, email)
var i User
err := row.Scan(
&i.ID,
&i.Username,
&i.Verified,
&i.RegistrationDate,
&i.Role,
&i.Deleted,
)
return i, err
}
const getUserByUsername = `-- name: GetUserByUsername :one
SELECT id, username, verified, registration_date, role, deleted FROM users
WHERE username = $1
`
func (q *Queries) GetUserByUsername(ctx context.Context, username string) (User, error) {
row := q.db.QueryRow(ctx, getUserByUsername, username)
var i User
err := row.Scan(
&i.ID,
&i.Username,
&i.Verified,
&i.RegistrationDate,
&i.Role,
&i.Deleted,
)
return i, err
}
const getValidConfirmationCodeByCode = `-- name: GetValidConfirmationCodeByCode :one
SELECT id, user_id, code_type, code_hash, expires_at, used, deleted FROM confirmation_codes
WHERE
user_id = $1 AND
code_type = $2 AND
expires_at > CURRENT_TIMESTAMP AND
used IS FALSE AND
code_hash = crypt($3::text, code_hash)
`
type GetValidConfirmationCodeByCodeParams struct {
UserID int64
CodeType int32
Code string
}
func (q *Queries) GetValidConfirmationCodeByCode(ctx context.Context, arg GetValidConfirmationCodeByCodeParams) (ConfirmationCode, error) {
row := q.db.QueryRow(ctx, getValidConfirmationCodeByCode, arg.UserID, arg.CodeType, arg.Code)
var i ConfirmationCode
err := row.Scan(
&i.ID,
&i.UserID,
&i.CodeType,
&i.CodeHash,
&i.ExpiresAt,
&i.Used,
&i.Deleted,
)
return i, err
}
const getValidConfirmationCodesByUsername = `-- name: GetValidConfirmationCodesByUsername :many
SELECT confirmation_codes.id, user_id, code_type, code_hash, expires_at, used, confirmation_codes.deleted, users.id, username, verified, registration_date, role, users.deleted FROM confirmation_codes
JOIN users on users.id = confirmation_codes.user_id
WHERE
users.username = $1::text AND
code_type = $2::integer AND
expires_at > CURRENT_TIMESTAMP AND
used IS FALSE
`
type GetValidConfirmationCodesByUsernameParams struct {
Username string
CodeType int32
}
type GetValidConfirmationCodesByUsernameRow struct {
ID int64
UserID int64
CodeType int32
CodeHash string
ExpiresAt pgtype.Timestamp
Used *bool
Deleted *bool
ID_2 int64
Username string
Verified *bool
RegistrationDate pgtype.Timestamp
Role int32
Deleted_2 *bool
}
func (q *Queries) GetValidConfirmationCodesByUsername(ctx context.Context, arg GetValidConfirmationCodesByUsernameParams) ([]GetValidConfirmationCodesByUsernameRow, error) {
rows, err := q.db.Query(ctx, getValidConfirmationCodesByUsername, arg.Username, arg.CodeType)
if err != nil {
return nil, err
}
defer rows.Close()
var items []GetValidConfirmationCodesByUsernameRow
for rows.Next() {
var i GetValidConfirmationCodesByUsernameRow
if err := rows.Scan(
&i.ID,
&i.UserID,
&i.CodeType,
&i.CodeHash,
&i.ExpiresAt,
&i.Used,
&i.Deleted,
&i.ID_2,
&i.Username,
&i.Verified,
&i.RegistrationDate,
&i.Role,
&i.Deleted_2,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getValidUserByLoginCredentials = `-- name: GetValidUserByLoginCredentials :one
SELECT
users.id, users.username, users.verified, users.registration_date, users.role, users.deleted,
linfo.password_hash,
linfo.totp_encrypted
FROM users
JOIN login_informations AS linfo ON users.id = linfo.user_id
LEFT JOIN banned_users AS banned ON users.id = banned.user_id
WHERE
users.username = $1 AND
users.verified IS TRUE AND -- Verified
users.deleted IS FALSE AND -- Not deleted
banned.user_id IS NULL AND -- Not banned
linfo.password_hash = crypt($2::text, linfo.password_hash)
`
type GetValidUserByLoginCredentialsParams struct {
Username string
Password string
}
type GetValidUserByLoginCredentialsRow struct {
ID int64
Username string
Verified *bool
RegistrationDate pgtype.Timestamp
Role int32
Deleted *bool
PasswordHash string
TotpEncrypted *string
}
func (q *Queries) GetValidUserByLoginCredentials(ctx context.Context, arg GetValidUserByLoginCredentialsParams) (GetValidUserByLoginCredentialsRow, error) {
row := q.db.QueryRow(ctx, getValidUserByLoginCredentials, arg.Username, arg.Password)
var i GetValidUserByLoginCredentialsRow
err := row.Scan(
&i.ID,
&i.Username,
&i.Verified,
&i.RegistrationDate,
&i.Role,
&i.Deleted,
&i.PasswordHash,
&i.TotpEncrypted,
)
return i, err
}
const getValidUserSessions = `-- name: GetValidUserSessions :many
SELECT id, user_id, guid, name, platform, latest_ip, login_time, last_refresh_exp_time, last_seen_date, terminated FROM sessions
WHERE
user_id = $1 AND terminated IS FALSE AND
last_refresh_exp_time > CURRENT_TIMESTAMP
`
func (q *Queries) GetValidUserSessions(ctx context.Context, userID int64) ([]Session, error) {
rows, err := q.db.Query(ctx, getValidUserSessions, userID)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Session
for rows.Next() {
var i Session
if err := rows.Scan(
&i.ID,
&i.UserID,
&i.Guid,
&i.Name,
&i.Platform,
&i.LatestIp,
&i.LoginTime,
&i.LastRefreshExpTime,
&i.LastSeenDate,
&i.Terminated,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const pruneExpiredConfirmationCodes = `-- name: PruneExpiredConfirmationCodes :exec
DELETE FROM confirmation_codes
WHERE expires_at < CURRENT_TIMESTAMP
`
func (q *Queries) PruneExpiredConfirmationCodes(ctx context.Context) error {
_, err := q.db.Exec(ctx, pruneExpiredConfirmationCodes)
return err
}
const pruneTerminatedSessions = `-- name: PruneTerminatedSessions :exec
DELETE FROM sessions
WHERE terminated IS TRUE
`
func (q *Queries) PruneTerminatedSessions(ctx context.Context) error {
_, err := q.db.Exec(ctx, pruneTerminatedSessions)
return err
}
const terminateAllSessionsForUserByUsername = `-- name: TerminateAllSessionsForUserByUsername :many
UPDATE sessions
SET terminated = TRUE
FROM users
WHERE sessions.user_id = users.id AND users.username = $1::text
RETURNING sessions.guid
`
func (q *Queries) TerminateAllSessionsForUserByUsername(ctx context.Context, username string) ([]pgtype.UUID, error) {
rows, err := q.db.Query(ctx, terminateAllSessionsForUserByUsername, username)
if err != nil {
return nil, err
}
defer rows.Close()
var items []pgtype.UUID
for rows.Next() {
var guid pgtype.UUID
if err := rows.Scan(&guid); err != nil {
return nil, err
}
items = append(items, guid)
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const updateBannedUser = `-- name: UpdateBannedUser :exec
UPDATE banned_users
SET
reason = COALESCE($2, reason),
expires_at = COALESCE($3, expires_at),
banned_by = COALESCE($4, banned_by),
pardoned = COALESCE($5, pardoned),
pardoned_by = COALESCE($6, pardoned_by)
WHERE id = $1
`
type UpdateBannedUserParams struct {
ID int64
Reason *string
ExpiresAt pgtype.Timestamp
BannedBy *string
Pardoned *bool
PardonedBy *string
}
func (q *Queries) UpdateBannedUser(ctx context.Context, arg UpdateBannedUserParams) error {
_, err := q.db.Exec(ctx, updateBannedUser,
arg.ID,
arg.Reason,
arg.ExpiresAt,
arg.BannedBy,
arg.Pardoned,
arg.PardonedBy,
)
return err
}
const updateConfirmationCode = `-- name: UpdateConfirmationCode :exec
UPDATE confirmation_codes
SET
used = COALESCE($2, used),
deleted = COALESCE($3, deleted)
WHERE id = $1
`
type UpdateConfirmationCodeParams struct {
ID int64
Used *bool
Deleted *bool
}
func (q *Queries) UpdateConfirmationCode(ctx context.Context, arg UpdateConfirmationCodeParams) error {
_, err := q.db.Exec(ctx, updateConfirmationCode, arg.ID, arg.Used, arg.Deleted)
return err
}
const updateLoginInformationByUsername = `-- name: UpdateLoginInformationByUsername :exec
UPDATE login_informations
SET
email = COALESCE($2, email),
password_hash = COALESCE($3::text, password_hash),
totp_encrypted = COALESCE($4, totp_encrypted),
email_2fa_enabled = COALESCE($5, email_2fa_enabled),
password_change_date = COALESCE($6, password_change_date)
FROM users
WHERE users.username = $1 AND login_informations.user_id = users.id
`
type UpdateLoginInformationByUsernameParams struct {
Username string
Email *string
PasswordHash string
TotpEncrypted *string
Email2faEnabled *bool
PasswordChangeDate pgtype.Timestamp
}
func (q *Queries) UpdateLoginInformationByUsername(ctx context.Context, arg UpdateLoginInformationByUsernameParams) error {
_, err := q.db.Exec(ctx, updateLoginInformationByUsername,
arg.Username,
arg.Email,
arg.PasswordHash,
arg.TotpEncrypted,
arg.Email2faEnabled,
arg.PasswordChangeDate,
)
return err
}
const updateProfileByUsername = `-- name: UpdateProfileByUsername :exec
UPDATE profiles
SET
name = COALESCE($2, name),
bio = COALESCE($3, bio),
birthday = COALESCE($4, birthday),
avatar_url = COALESCE($7, avatar_url),
color = COALESCE($5, color),
color_grad = COALESCE($6, color_grad)
FROM users
WHERE username = $1
`
type UpdateProfileByUsernameParams struct {
Username string
Name string
Bio string
Birthday pgtype.Timestamp
Color string
ColorGrad string
AvatarUrl *string
}
func (q *Queries) UpdateProfileByUsername(ctx context.Context, arg UpdateProfileByUsernameParams) error {
_, err := q.db.Exec(ctx, updateProfileByUsername,
arg.Username,
arg.Name,
arg.Bio,
arg.Birthday,
arg.Color,
arg.ColorGrad,
arg.AvatarUrl,
)
return err
}
const updateProfileSettingsByUsername = `-- name: UpdateProfileSettingsByUsername :exec
UPDATE profile_settings ps
SET
hide_fulfilled = COALESCE($2, ps.hide_fulfilled),
hide_profile_details = COALESCE($3, ps.hide_profile_details),
hide_for_unauthenticated = COALESCE($4, ps.hide_for_unauthenticated),
hide_birthday = COALESCE($5, ps.hide_birthday),
hide_dates = COALESCE($6, ps.hide_dates),
captcha = COALESCE($7, ps.captcha),
followers_only_interaction = COALESCE($8, ps.followers_only_interaction)
FROM profiles p
JOIN users u ON p.user_id = u.id
WHERE ps.profile_id = p.id AND u.username = $1
`
type UpdateProfileSettingsByUsernameParams struct {
Username string
HideFulfilled bool
HideProfileDetails bool
HideForUnauthenticated bool
HideBirthday bool
HideDates bool
Captcha bool
FollowersOnlyInteraction bool
}
func (q *Queries) UpdateProfileSettingsByUsername(ctx context.Context, arg UpdateProfileSettingsByUsernameParams) error {
_, err := q.db.Exec(ctx, updateProfileSettingsByUsername,
arg.Username,
arg.HideFulfilled,
arg.HideProfileDetails,
arg.HideForUnauthenticated,
arg.HideBirthday,
arg.HideDates,
arg.Captcha,
arg.FollowersOnlyInteraction,
)
return err
}
const updateSession = `-- name: UpdateSession :exec
UPDATE sessions
SET
name = COALESCE($2, name),
platform = COALESCE($3, platform),
latest_ip = COALESCE($4, latest_ip),
login_time = COALESCE($5, login_time),
last_refresh_exp_time = COALESCE($6, last_refresh_exp_time),
last_seen_date = COALESCE($7, last_seen_date),
terminated = COALESCE($8, terminated)
WHERE id = $1
`
type UpdateSessionParams struct {
ID int64
Name *string
Platform *string
LatestIp *string
LoginTime pgtype.Timestamp
LastRefreshExpTime pgtype.Timestamp
LastSeenDate pgtype.Timestamp
Terminated *bool
}
func (q *Queries) UpdateSession(ctx context.Context, arg UpdateSessionParams) error {
_, err := q.db.Exec(ctx, updateSession,
arg.ID,
arg.Name,
arg.Platform,
arg.LatestIp,
arg.LoginTime,
arg.LastRefreshExpTime,
arg.LastSeenDate,
arg.Terminated,
)
return err
}
const updateUser = `-- name: UpdateUser :exec
UPDATE users
SET
verified = COALESCE($2, verified),
deleted = COALESCE($3, deleted)
WHERE id = $1
`
type UpdateUserParams struct {
ID int64
Verified *bool
Deleted *bool
}
func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) error {
_, err := q.db.Exec(ctx, updateUser, arg.ID, arg.Verified, arg.Deleted)
return err
}
const updateUserByUsername = `-- name: UpdateUserByUsername :exec
UPDATE users
SET verified = $2, deleted = $3
WHERE username = $1
`
type UpdateUserByUsernameParams struct {
Username string
Verified *bool
Deleted *bool
}
func (q *Queries) UpdateUserByUsername(ctx context.Context, arg UpdateUserByUsernameParams) error {
_, err := q.db.Exec(ctx, updateUserByUsername, arg.Username, arg.Verified, arg.Deleted)
return err
}