Help us shape the future of Go! Take the 2026 Go Developer Survey

db

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AcceptInvitationParams

type AcceptInvitationParams struct {
	Now *time.Time
	ID  uuid.UUID
}

type AuthAuthEvent

type AuthAuthEvent struct {
	ID        uuid.UUID
	UserID    *uuid.UUID
	ActorID   *uuid.UUID
	Event     string
	Ip        *netip.Addr
	UserAgent *string
	Metadata  []byte
	CreatedAt time.Time
	UpdatedAt time.Time
}

type AuthEmailToken

type AuthEmailToken struct {
	ID             uuid.UUID
	UserID         uuid.UUID
	Kind           string
	TokenHash      []byte
	NewEmail       *string
	FailedAttempts int32
	ExpiresAt      time.Time
	UsedAt         *time.Time
	CreatedAt      time.Time
	UpdatedAt      time.Time
}

type AuthInvitation

type AuthInvitation struct {
	ID             uuid.UUID
	OrganizationID uuid.UUID
	Email          string
	Role           string
	TokenHash      []byte
	InvitedBy      uuid.UUID
	ExpiresAt      time.Time
	AcceptedAt     *time.Time
	CreatedAt      time.Time
	UpdatedAt      time.Time
}

type AuthLoginFailure

type AuthLoginFailure struct {
	ID            uuid.UUID
	Key           string
	Failures      int32
	LastFailedAt  time.Time
	NextAllowedAt time.Time
	CreatedAt     time.Time
	UpdatedAt     time.Time
}

type AuthMembership

type AuthMembership struct {
	ID             uuid.UUID
	OrganizationID uuid.UUID
	UserID         uuid.UUID
	Role           string
	CreatedAt      time.Time
	UpdatedAt      time.Time
}

type AuthOauthAccount

type AuthOauthAccount struct {
	ID             uuid.UUID
	UserID         uuid.UUID
	Provider       string
	ProviderUserID string
	Email          string
	CreatedAt      time.Time
	UpdatedAt      time.Time
}

type AuthOauthFlow

type AuthOauthFlow struct {
	ID                    uuid.UUID
	StateHash             []byte
	Provider              string
	Purpose               string
	UserID                *uuid.UUID
	Client                string
	ClientChallenge       []byte
	PkceVerifierEncrypted []byte
	Nonce                 string
	ExpiresAt             time.Time
	UsedAt                *time.Time
	CreatedAt             time.Time
	UpdatedAt             time.Time
}

type AuthOrganization

type AuthOrganization struct {
	ID        uuid.UUID
	Name      string
	CreatedAt time.Time
	UpdatedAt time.Time
}

type AuthRateLimit

type AuthRateLimit struct {
	ID          uuid.UUID
	Key         string
	WindowStart time.Time
	ExpiresAt   time.Time
	Count       int32
	CreatedAt   time.Time
	UpdatedAt   time.Time
}

type AuthRecoveryCode

type AuthRecoveryCode struct {
	ID        uuid.UUID
	UserID    uuid.UUID
	CodeHash  []byte
	UsedAt    *time.Time
	CreatedAt time.Time
	UpdatedAt time.Time
}

type AuthSession

type AuthSession struct {
	ID                uuid.UUID
	UserID            uuid.UUID
	TokenHash         []byte
	Client            string
	Ip                *netip.Addr
	UserAgent         *string
	LastUsedAt        time.Time
	ExpiresAt         time.Time
	AbsoluteExpiresAt time.Time
	CreatedAt         time.Time
	UpdatedAt         time.Time
}

type AuthTotpSecret

type AuthTotpSecret struct {
	UserID          uuid.UUID
	SecretEncrypted []byte
	LastUsedStep    int64
	ConfirmedAt     *time.Time
	CreatedAt       time.Time
	UpdatedAt       time.Time
}

type AuthTwoFactorChallenge

type AuthTwoFactorChallenge struct {
	ID             uuid.UUID
	UserID         uuid.UUID
	TokenHash      []byte
	Client         string
	FailedAttempts int32
	ExpiresAt      time.Time
	UsedAt         *time.Time
	CreatedAt      time.Time
	UpdatedAt      time.Time
}

type AuthTwoFactorFailure

type AuthTwoFactorFailure struct {
	ID        uuid.UUID
	UserID    uuid.UUID
	CreatedAt time.Time
	UpdatedAt time.Time
}

type AuthUsedAppleNonce added in v1.4.0

type AuthUsedAppleNonce struct {
	ID        uuid.UUID
	NonceHash []byte
	ExpiresAt time.Time
	CreatedAt time.Time
	UpdatedAt time.Time
}

type AuthUser

type AuthUser struct {
	ID                uuid.UUID
	Email             string
	EmailVerifiedAt   *time.Time
	PasswordHash      *string
	TwoFactorRequired bool
	CreatedAt         time.Time
	UpdatedAt         time.Time
}

type AuthUserRole

type AuthUserRole struct {
	UserID    uuid.UUID
	Role      string
	CreatedAt time.Time
	UpdatedAt time.Time
}

type ClearPasswordParams

type ClearPasswordParams struct {
	Now time.Time
	ID  uuid.UUID
}

type ConfirmTOTPSecretParams

type ConfirmTOTPSecretParams struct {
	Now    *time.Time
	Step   int64
	UserID uuid.UUID
}

type CountOwnersParams

type CountOwnersParams struct {
	OrganizationID uuid.UUID
	OwnerRole      string
}

type CreateAuthEventParams

type CreateAuthEventParams struct {
	ID        uuid.UUID
	UserID    *uuid.UUID
	ActorID   *uuid.UUID
	Event     string
	Ip        *netip.Addr
	UserAgent *string
	Metadata  []byte
	Now       time.Time
}

type CreateEmailTokenParams

type CreateEmailTokenParams struct {
	ID        uuid.UUID
	UserID    uuid.UUID
	Kind      string
	TokenHash []byte
	NewEmail  *string
	ExpiresAt time.Time
	Now       time.Time
}

type CreateInvitationParams

type CreateInvitationParams struct {
	ID             uuid.UUID
	OrganizationID uuid.UUID
	Email          string
	Role           string
	TokenHash      []byte
	InvitedBy      uuid.UUID
	ExpiresAt      time.Time
	Now            time.Time
}

type CreateMembershipParams

type CreateMembershipParams struct {
	ID             uuid.UUID
	OrganizationID uuid.UUID
	UserID         uuid.UUID
	Role           string
	Now            time.Time
}

type CreateOAuthAccountParams

type CreateOAuthAccountParams struct {
	ID             uuid.UUID
	UserID         uuid.UUID
	Provider       string
	ProviderUserID string
	Email          string
	Now            time.Time
}

type CreateOAuthFlowParams

type CreateOAuthFlowParams struct {
	ID                    uuid.UUID
	StateHash             []byte
	Provider              string
	Purpose               string
	UserID                *uuid.UUID
	Client                string
	ClientChallenge       []byte
	PkceVerifierEncrypted []byte
	Nonce                 string
	ExpiresAt             time.Time
	Now                   time.Time
}

type CreateOrganizationParams

type CreateOrganizationParams struct {
	ID   uuid.UUID
	Name string
	Now  time.Time
}

type CreateRecoveryCodeParams

type CreateRecoveryCodeParams struct {
	ID       uuid.UUID
	UserID   uuid.UUID
	CodeHash []byte
	Now      time.Time
}

type CreateSessionParams

type CreateSessionParams struct {
	ID                uuid.UUID
	UserID            uuid.UUID
	TokenHash         []byte
	Client            string
	Ip                *netip.Addr
	UserAgent         *string
	Now               time.Time
	ExpiresAt         time.Time
	AbsoluteExpiresAt time.Time
}

type CreateTwoFactorChallengeParams

type CreateTwoFactorChallengeParams struct {
	ID        uuid.UUID
	UserID    uuid.UUID
	TokenHash []byte
	Client    string
	ExpiresAt time.Time
	Now       time.Time
}

type CreateTwoFactorFailureParams

type CreateTwoFactorFailureParams struct {
	ID     uuid.UUID
	UserID uuid.UUID
	Now    time.Time
}

type CreateUserParams

type CreateUserParams struct {
	ID           uuid.UUID
	Email        string
	PasswordHash *string
	Now          time.Time
}

type DBTX

type DBTX interface {
	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
	QueryRow(context.Context, string, ...interface{}) pgx.Row
}

type DeleteEndedTwoFactorChallengesParams

type DeleteEndedTwoFactorChallengesParams struct {
	Now               time.Time
	MaxFailedAttempts int32
}

type DeleteMembershipParams

type DeleteMembershipParams struct {
	OrganizationID uuid.UUID
	UserID         uuid.UUID
}

type DeleteOAuthAccountParams

type DeleteOAuthAccountParams struct {
	ID     uuid.UUID
	UserID uuid.UUID
}

type DeleteOldLoginFailuresParams

type DeleteOldLoginFailuresParams struct {
	ResetBefore time.Time
	Now         time.Time
}

type DeleteOldTwoFactorFailuresParams

type DeleteOldTwoFactorFailuresParams struct {
	UserID uuid.UUID
	Since  time.Time
}

type DeleteSessionParams

type DeleteSessionParams struct {
	ID     uuid.UUID
	UserID uuid.UUID
}

type DeleteSpentTwoFactorChallengesParams

type DeleteSpentTwoFactorChallengesParams struct {
	UserID            uuid.UUID
	Now               time.Time
	MaxFailedAttempts int32
}

type DeleteUnusedEmailTokensParams

type DeleteUnusedEmailTokensParams struct {
	UserID uuid.UUID
	Kind   string
}

type DeleteUserSessionsExceptParams

type DeleteUserSessionsExceptParams struct {
	UserID uuid.UUID
	KeepID uuid.UUID
}

type ExtendSessionParams

type ExtendSessionParams struct {
	Now       time.Time
	ExpiresAt time.Time
	ID        uuid.UUID
}

type GetEmailTokenByHashParams

type GetEmailTokenByHashParams struct {
	TokenHash []byte
	Kind      string
}

type GetLoginHistoryParams

type GetLoginHistoryParams struct {
	UserID    *uuid.UUID
	Since     time.Time
	UserAgent *string
	Ip        netip.Addr
	Bits      int32
}

type GetLoginHistoryRow

type GetLoginHistoryRow struct {
	AnyLogin bool
	Seen     bool
}

type GetMemberOrganizationParams

type GetMemberOrganizationParams struct {
	OrganizationID uuid.UUID
	UserID         uuid.UUID
}

type GetMemberOrganizationRow

type GetMemberOrganizationRow struct {
	ID        uuid.UUID
	Name      string
	CreatedAt time.Time
	UpdatedAt time.Time
	Role      string
}

type GetMembershipParams

type GetMembershipParams struct {
	OrganizationID uuid.UUID
	UserID         uuid.UUID
}

type GetMembershipRoleParams

type GetMembershipRoleParams struct {
	OrganizationID uuid.UUID
	UserID         uuid.UUID
}

type GetOAuthAccountParams

type GetOAuthAccountParams struct {
	Provider       string
	ProviderUserID string
}

type GetPendingInvitationForEmailParams

type GetPendingInvitationForEmailParams struct {
	OrganizationID uuid.UUID
	Email          string
}

type GetPendingInvitationInOrganizationParams

type GetPendingInvitationInOrganizationParams struct {
	OrganizationID uuid.UUID
	ID             uuid.UUID
}

type GetRateLimitCountParams

type GetRateLimitCountParams struct {
	Key         string
	WindowStart time.Time
}

type GetUserWithTwoFactorParams

type GetUserWithTwoFactorParams struct {
	Roles []string
	ID    uuid.UUID
}

type GetUserWithTwoFactorRow

type GetUserWithTwoFactorRow struct {
	AuthUser         AuthUser
	Privileged       bool
	TwoFactorEnabled bool
}

type HitRateLimitParams

type HitRateLimitParams struct {
	ID          uuid.UUID
	Key         string
	WindowStart time.Time
	ExpiresAt   time.Time
	Now         time.Time
}

type IsMemberByEmailParams

type IsMemberByEmailParams struct {
	OrganizationID uuid.UUID
	Email          string
}

type LatestEmailTokenCreatedAtParams

type LatestEmailTokenCreatedAtParams struct {
	UserID uuid.UUID
	Kind   string
}

type ListActiveSessionsParams

type ListActiveSessionsParams struct {
	UserID uuid.UUID
	Now    time.Time
}

type ListAuthEventsParams

type ListAuthEventsParams struct {
	UserID   *uuid.UUID
	Before   *uuid.UUID
	PageSize int32
}

type ListMembersParams

type ListMembersParams struct {
	OrganizationID uuid.UUID
	After          *uuid.UUID
	MaxRows        int32
}

type ListMembersRow

type ListMembersRow struct {
	ID        uuid.UUID
	UserID    uuid.UUID
	Email     string
	Role      string
	CreatedAt time.Time
}

type ListPendingInvitationsParams

type ListPendingInvitationsParams struct {
	OrganizationID uuid.UUID
	Now            time.Time
	After          *uuid.UUID
	MaxRows        int32
}

type ListUserOrganizationsRow

type ListUserOrganizationsRow struct {
	ID        uuid.UUID
	Name      string
	CreatedAt time.Time
	UpdatedAt time.Time
	Role      string
}

type MarkEmailVerifiedParams

type MarkEmailVerifiedParams struct {
	Now time.Time
	ID  uuid.UUID
}

type NthRecentTwoFactorFailureParams

type NthRecentTwoFactorFailureParams struct {
	UserID uuid.UUID
	Since  time.Time
	N      int32
}

type Queries

type Queries struct {
	// contains filtered or unexported fields
}

func New

func New(db DBTX) *Queries

func (*Queries) AcceptInvitation

func (q *Queries) AcceptInvitation(ctx context.Context, arg AcceptInvitationParams) (int64, error)

Marks an invitation accepted only if it still is pending and unexpired, so two requests with the same link can't both use it.

func (*Queries) ClearPassword

func (q *Queries) ClearPassword(ctx context.Context, arg ClearPasswordParams) error

func (*Queries) ConfirmTOTPSecret

func (q *Queries) ConfirmTOTPSecret(ctx context.Context, arg ConfirmTOTPSecretParams) error

func (*Queries) CountOAuthAccounts

func (q *Queries) CountOAuthAccounts(ctx context.Context, userID uuid.UUID) (int64, error)

func (*Queries) CountOwners

func (q *Queries) CountOwners(ctx context.Context, arg CountOwnersParams) (int64, error)

func (*Queries) CountUnusedRecoveryCodes

func (q *Queries) CountUnusedRecoveryCodes(ctx context.Context, userID uuid.UUID) (int64, error)

func (*Queries) CreateAuthEvent

func (q *Queries) CreateAuthEvent(ctx context.Context, arg CreateAuthEventParams) error

func (*Queries) CreateEmailToken

func (q *Queries) CreateEmailToken(ctx context.Context, arg CreateEmailTokenParams) (AuthEmailToken, error)

func (*Queries) CreateInvitation

func (q *Queries) CreateInvitation(ctx context.Context, arg CreateInvitationParams) (AuthInvitation, error)

func (*Queries) CreateMembership

func (q *Queries) CreateMembership(ctx context.Context, arg CreateMembershipParams) error

func (*Queries) CreateOAuthAccount

func (q *Queries) CreateOAuthAccount(ctx context.Context, arg CreateOAuthAccountParams) error

func (*Queries) CreateOAuthFlow

func (q *Queries) CreateOAuthFlow(ctx context.Context, arg CreateOAuthFlowParams) error

func (*Queries) CreateOrganization

func (q *Queries) CreateOrganization(ctx context.Context, arg CreateOrganizationParams) (AuthOrganization, error)

func (*Queries) CreateRecoveryCode

func (q *Queries) CreateRecoveryCode(ctx context.Context, arg CreateRecoveryCodeParams) error

func (*Queries) CreateSession

func (q *Queries) CreateSession(ctx context.Context, arg CreateSessionParams) (AuthSession, error)

func (*Queries) CreateTwoFactorChallenge

func (q *Queries) CreateTwoFactorChallenge(ctx context.Context, arg CreateTwoFactorChallengeParams) error

func (*Queries) CreateTwoFactorFailure

func (q *Queries) CreateTwoFactorFailure(ctx context.Context, arg CreateTwoFactorFailureParams) error

func (*Queries) CreateUser

func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (AuthUser, error)

func (*Queries) DeleteAuthEventsBefore

func (q *Queries) DeleteAuthEventsBefore(ctx context.Context, before time.Time) (int64, error)

func (*Queries) DeleteEndedRateLimits

func (q *Queries) DeleteEndedRateLimits(ctx context.Context, now time.Time) (int64, error)

func (*Queries) DeleteEndedTwoFactorChallenges

func (q *Queries) DeleteEndedTwoFactorChallenges(ctx context.Context, arg DeleteEndedTwoFactorChallengesParams) (int64, error)

func (*Queries) DeleteExpiredAppleNonces added in v1.4.0

func (q *Queries) DeleteExpiredAppleNonces(ctx context.Context, now time.Time) (int64, error)

func (*Queries) DeleteExpiredSessions

func (q *Queries) DeleteExpiredSessions(ctx context.Context, now time.Time) (int64, error)

func (*Queries) DeleteInvitation

func (q *Queries) DeleteInvitation(ctx context.Context, id uuid.UUID) error

func (*Queries) DeleteLoginFailures

func (q *Queries) DeleteLoginFailures(ctx context.Context, key string) error

func (*Queries) DeleteMembership

func (q *Queries) DeleteMembership(ctx context.Context, arg DeleteMembershipParams) error

func (*Queries) DeleteOAuthAccount

func (q *Queries) DeleteOAuthAccount(ctx context.Context, arg DeleteOAuthAccountParams) (string, error)

func (*Queries) DeleteOldLoginFailures

func (q *Queries) DeleteOldLoginFailures(ctx context.Context, arg DeleteOldLoginFailuresParams) (int64, error)

func (*Queries) DeleteOldTwoFactorFailures

func (q *Queries) DeleteOldTwoFactorFailures(ctx context.Context, arg DeleteOldTwoFactorFailuresParams) error

func (*Queries) DeleteRecoveryCodes

func (q *Queries) DeleteRecoveryCodes(ctx context.Context, userID uuid.UUID) error

func (*Queries) DeleteSession

func (q *Queries) DeleteSession(ctx context.Context, arg DeleteSessionParams) (int64, error)

func (*Queries) DeleteSpentEmailTokens

func (q *Queries) DeleteSpentEmailTokens(ctx context.Context, now time.Time) (int64, error)

func (*Queries) DeleteSpentOAuthFlows

func (q *Queries) DeleteSpentOAuthFlows(ctx context.Context, now time.Time) (int64, error)

func (*Queries) DeleteSpentTwoFactorChallenges

func (q *Queries) DeleteSpentTwoFactorChallenges(ctx context.Context, arg DeleteSpentTwoFactorChallengesParams) error

Also clears out the user's challenges that can no longer be used.

func (*Queries) DeleteTOTPSecret

func (q *Queries) DeleteTOTPSecret(ctx context.Context, userID uuid.UUID) error

func (*Queries) DeleteTwoFactorChallenges

func (q *Queries) DeleteTwoFactorChallenges(ctx context.Context, userID uuid.UUID) error

func (*Queries) DeleteTwoFactorFailuresBefore

func (q *Queries) DeleteTwoFactorFailuresBefore(ctx context.Context, before time.Time) (int64, error)

func (*Queries) DeleteUnusedEmailTokens

func (q *Queries) DeleteUnusedEmailTokens(ctx context.Context, arg DeleteUnusedEmailTokensParams) error

func (*Queries) DeleteUnusedUserEmailTokens

func (q *Queries) DeleteUnusedUserEmailTokens(ctx context.Context, userID uuid.UUID) error

func (*Queries) DeleteUserOAuthAccounts added in v1.2.0

func (q *Queries) DeleteUserOAuthAccounts(ctx context.Context, userID uuid.UUID) error

func (*Queries) DeleteUserRole

func (q *Queries) DeleteUserRole(ctx context.Context, userID uuid.UUID) error

func (*Queries) DeleteUserSessions

func (q *Queries) DeleteUserSessions(ctx context.Context, userID uuid.UUID) (int64, error)

func (*Queries) DeleteUserSessionsExcept

func (q *Queries) DeleteUserSessionsExcept(ctx context.Context, arg DeleteUserSessionsExceptParams) (int64, error)

func (*Queries) ExtendSession

func (q *Queries) ExtendSession(ctx context.Context, arg ExtendSessionParams) error

func (*Queries) GetEmailTokenByHash

func (q *Queries) GetEmailTokenByHash(ctx context.Context, arg GetEmailTokenByHashParams) (AuthEmailToken, error)

func (*Queries) GetInvitationByTokenHash

func (q *Queries) GetInvitationByTokenHash(ctx context.Context, tokenHash []byte) (AuthInvitation, error)

func (*Queries) GetLoginHistory

func (q *Queries) GetLoginHistory(ctx context.Context, arg GetLoginHistoryParams) (GetLoginHistoryRow, error)

Whether a user has logged in before at all, and whether they have since @since from this user agent and network (@ip masked to @bits).

func (*Queries) GetLoginWaits

func (q *Queries) GetLoginWaits(ctx context.Context, keys []string) ([]time.Time, error)

func (*Queries) GetMemberOrganization

func (q *Queries) GetMemberOrganization(ctx context.Context, arg GetMemberOrganizationParams) (GetMemberOrganizationRow, error)

func (*Queries) GetMembership

func (q *Queries) GetMembership(ctx context.Context, arg GetMembershipParams) (AuthMembership, error)

func (*Queries) GetMembershipRole

func (q *Queries) GetMembershipRole(ctx context.Context, arg GetMembershipRoleParams) (string, error)

func (*Queries) GetOAuthAccount

func (q *Queries) GetOAuthAccount(ctx context.Context, arg GetOAuthAccountParams) (AuthOauthAccount, error)

func (*Queries) GetOAuthFlowForUpdate

func (q *Queries) GetOAuthFlowForUpdate(ctx context.Context, stateHash []byte) (AuthOauthFlow, error)

Locks the flow, so two requests can't both finish it.

func (*Queries) GetPendingInvitationForEmail

func (q *Queries) GetPendingInvitationForEmail(ctx context.Context, arg GetPendingInvitationForEmailParams) (AuthInvitation, error)

func (*Queries) GetPendingInvitationInOrganization

func (q *Queries) GetPendingInvitationInOrganization(ctx context.Context, arg GetPendingInvitationInOrganizationParams) (AuthInvitation, error)

func (*Queries) GetRateLimitCount

func (q *Queries) GetRateLimitCount(ctx context.Context, arg GetRateLimitCountParams) (int32, error)

func (*Queries) GetSessionByTokenHash

func (q *Queries) GetSessionByTokenHash(ctx context.Context, tokenHash []byte) (AuthSession, error)

func (*Queries) GetTOTPSecret

func (q *Queries) GetTOTPSecret(ctx context.Context, userID uuid.UUID) (AuthTotpSecret, error)

func (*Queries) GetTOTPSecretForUpdate

func (q *Queries) GetTOTPSecretForUpdate(ctx context.Context, userID uuid.UUID) (AuthTotpSecret, error)

Locks the row, so two requests with the same code can't both use it.

func (*Queries) GetTwoFactorChallengeForUpdate

func (q *Queries) GetTwoFactorChallengeForUpdate(ctx context.Context, tokenHash []byte) (AuthTwoFactorChallenge, error)

Locks the challenge, so concurrent requests count wrong codes and use it one at a time.

func (*Queries) GetUserByEmail

func (q *Queries) GetUserByEmail(ctx context.Context, email string) (AuthUser, error)

Matches idx_users_email, so emails are found regardless of case.

func (*Queries) GetUserByEmailForUpdate

func (q *Queries) GetUserByEmailForUpdate(ctx context.Context, email string) (AuthUser, error)

Locks the user, so a concurrent sign-in or sign-up with the same email waits.

func (*Queries) GetUserByID

func (q *Queries) GetUserByID(ctx context.Context, id uuid.UUID) (AuthUser, error)

func (*Queries) GetUserRole

func (q *Queries) GetUserRole(ctx context.Context, userID uuid.UUID) (string, error)

func (*Queries) GetUserWithTwoFactor

func (q *Queries) GetUserWithTwoFactor(ctx context.Context, arg GetUserWithTwoFactorParams) (GetUserWithTwoFactorRow, error)

The user, with what decides their 2FA rules: whether they hold one of @roles (Config.TwoFactorRoles) as an app role or in any organization, and whether they have 2FA on.

func (*Queries) HitRateLimit

func (q *Queries) HitRateLimit(ctx context.Context, arg HitRateLimitParams) (int32, error)

Counts one more hit in the window, atomically, and returns the total.

func (*Queries) IsMemberByEmail

func (q *Queries) IsMemberByEmail(ctx context.Context, arg IsMemberByEmailParams) (bool, error)

func (*Queries) LatestEmailTokenCreatedAt

func (q *Queries) LatestEmailTokenCreatedAt(ctx context.Context, arg LatestEmailTokenCreatedAtParams) (time.Time, error)

func (*Queries) ListActiveSessions

func (q *Queries) ListActiveSessions(ctx context.Context, arg ListActiveSessionsParams) ([]AuthSession, error)

func (*Queries) ListAuthEvents

func (q *Queries) ListAuthEvents(ctx context.Context, arg ListAuthEventsParams) ([]AuthAuthEvent, error)

A page of a user's events, newest first. IDs are UUIDv7, so they sort by time; @before is the last ID of the previous page.

func (*Queries) ListMembers

func (q *Queries) ListMembers(ctx context.Context, arg ListMembersParams) ([]ListMembersRow, error)

Membership IDs are UUIDv7, so ordering by ID lists members in the order they joined, and the last ID on a page is the cursor for the next.

func (*Queries) ListOAuthAccounts

func (q *Queries) ListOAuthAccounts(ctx context.Context, userID uuid.UUID) ([]AuthOauthAccount, error)

func (*Queries) ListPendingInvitations

func (q *Queries) ListPendingInvitations(ctx context.Context, arg ListPendingInvitationsParams) ([]AuthInvitation, error)

Invitation IDs are UUIDv7, so ordering by ID lists them oldest first, and the last ID on a page is the cursor for the next.

func (*Queries) ListUserOrganizations

func (q *Queries) ListUserOrganizations(ctx context.Context, userID uuid.UUID) ([]ListUserOrganizationsRow, error)

func (*Queries) LockOrganization

func (q *Queries) LockOrganization(ctx context.Context, id uuid.UUID) (uuid.UUID, error)

Serializes changes to an organization's members, so two owners demoting each other at once can't leave it with none.

func (*Queries) LockUser

func (q *Queries) LockUser(ctx context.Context, id uuid.UUID) (uuid.UUID, error)

Serializes token creation per user, so concurrent requests can't both pass the cooldown check.

func (*Queries) MarkEmailVerified

func (q *Queries) MarkEmailVerified(ctx context.Context, arg MarkEmailVerifiedParams) error

Keeps the original verification time if the email was already verified.

func (*Queries) NthRecentTwoFactorFailure

func (q *Queries) NthRecentTwoFactorFailure(ctx context.Context, arg NthRecentTwoFactorFailureParams) (time.Time, error)

Returns the time of the user's nth most recent wrong code since @since (counting from 0), if there are that many.

func (*Queries) RecordEmailTokenFailure

func (q *Queries) RecordEmailTokenFailure(ctx context.Context, arg RecordEmailTokenFailureParams) error

func (*Queries) RecordLoginFailure

func (q *Queries) RecordLoginFailure(ctx context.Context, arg RecordLoginFailureParams) (int32, error)

Counts one more failure, starting over if the last was before @reset_before, and returns the count.

func (*Queries) RecordTOTPStep

func (q *Queries) RecordTOTPStep(ctx context.Context, arg RecordTOTPStepParams) error

func (*Queries) RecordTwoFactorChallengeFailure

func (q *Queries) RecordTwoFactorChallengeFailure(ctx context.Context, arg RecordTwoFactorChallengeFailureParams) error

func (*Queries) RenameOrganization

func (q *Queries) RenameOrganization(ctx context.Context, arg RenameOrganizationParams) (AuthOrganization, error)

func (*Queries) SetLoginNextAllowed

func (q *Queries) SetLoginNextAllowed(ctx context.Context, arg SetLoginNextAllowedParams) error

func (*Queries) SetMembershipRole

func (q *Queries) SetMembershipRole(ctx context.Context, arg SetMembershipRoleParams) error

func (*Queries) SetTwoFactorRequired

func (q *Queries) SetTwoFactorRequired(ctx context.Context, arg SetTwoFactorRequiredParams) (int64, error)

func (*Queries) SetUserRole

func (q *Queries) SetUserRole(ctx context.Context, arg SetUserRoleParams) error

func (*Queries) UndoRateLimitHit added in v1.2.0

func (q *Queries) UndoRateLimitHit(ctx context.Context, arg UndoRateLimitHitParams) error

Takes back one hit. A window's row only exists with a count of at least one, so the last hit is taken back by deleting it.

func (*Queries) UpdatePasswordHash

func (q *Queries) UpdatePasswordHash(ctx context.Context, arg UpdatePasswordHashParams) error

func (*Queries) UpdateUserEmail

func (q *Queries) UpdateUserEmail(ctx context.Context, arg UpdateUserEmailParams) error

func (*Queries) UpsertPendingTOTPSecret

func (q *Queries) UpsertPendingTOTPSecret(ctx context.Context, arg UpsertPendingTOTPSecretParams) (int64, error)

Starts (or restarts) setup. An already confirmed secret is left alone.

func (*Queries) UseAppleNonce added in v1.4.0

func (q *Queries) UseAppleNonce(ctx context.Context, arg UseAppleNonceParams) (int64, error)

Records that an Apple identity token with this nonce signed someone in. It affects no rows if a token that hasn't expired already used the nonce: that's a replay. An expired one's row is reused, since its token is refused anyway. The row has to have expired before @now, which is taken before the token's expiry was checked, so the same token can't slip through at the moment it expires.

func (*Queries) UseEmailToken

func (q *Queries) UseEmailToken(ctx context.Context, arg UseEmailTokenParams) (int64, error)

Marks a token used, only if it's still usable. Checking again here, not just at lookup, means two requests racing with the same token can't both use it.

func (*Queries) UseOAuthFlow

func (q *Queries) UseOAuthFlow(ctx context.Context, arg UseOAuthFlowParams) error

func (*Queries) UseRecoveryCode

func (q *Queries) UseRecoveryCode(ctx context.Context, arg UseRecoveryCodeParams) (int64, error)

Spends a recovery code, only if it's unused.

func (*Queries) UseTwoFactorChallenge

func (q *Queries) UseTwoFactorChallenge(ctx context.Context, arg UseTwoFactorChallengeParams) error

func (*Queries) UserHasOAuthProvider

func (q *Queries) UserHasOAuthProvider(ctx context.Context, arg UserHasOAuthProviderParams) (bool, error)

func (*Queries) WithTx

func (q *Queries) WithTx(tx pgx.Tx) *Queries

type RecordEmailTokenFailureParams

type RecordEmailTokenFailureParams struct {
	Now time.Time
	ID  uuid.UUID
}

type RecordLoginFailureParams

type RecordLoginFailureParams struct {
	ID          uuid.UUID
	Key         string
	Now         time.Time
	ResetBefore time.Time
}

type RecordTOTPStepParams

type RecordTOTPStepParams struct {
	Step   int64
	Now    time.Time
	UserID uuid.UUID
}

type RecordTwoFactorChallengeFailureParams

type RecordTwoFactorChallengeFailureParams struct {
	Now time.Time
	ID  uuid.UUID
}

type RenameOrganizationParams

type RenameOrganizationParams struct {
	Name string
	Now  time.Time
	ID   uuid.UUID
}

type SetLoginNextAllowedParams

type SetLoginNextAllowedParams struct {
	NextAllowedAt time.Time
	Now           time.Time
	Key           string
}

type SetMembershipRoleParams

type SetMembershipRoleParams struct {
	Role           string
	Now            time.Time
	OrganizationID uuid.UUID
	UserID         uuid.UUID
}

type SetTwoFactorRequiredParams

type SetTwoFactorRequiredParams struct {
	Required bool
	Now      time.Time
	ID       uuid.UUID
}

type SetUserRoleParams

type SetUserRoleParams struct {
	UserID uuid.UUID
	Role   string
	Now    time.Time
}

type UndoRateLimitHitParams added in v1.2.0

type UndoRateLimitHitParams struct {
	Now         time.Time
	Key         string
	WindowStart time.Time
}

type UpdatePasswordHashParams

type UpdatePasswordHashParams struct {
	PasswordHash *string
	Now          time.Time
	ID           uuid.UUID
}

type UpdateUserEmailParams

type UpdateUserEmailParams struct {
	Email string
	Now   *time.Time
	ID    uuid.UUID
}

type UpsertPendingTOTPSecretParams

type UpsertPendingTOTPSecretParams struct {
	UserID          uuid.UUID
	SecretEncrypted []byte
	Now             time.Time
}

type UseAppleNonceParams added in v1.4.0

type UseAppleNonceParams struct {
	ID        uuid.UUID
	NonceHash []byte
	ExpiresAt time.Time
	Now       time.Time
}

type UseEmailTokenParams

type UseEmailTokenParams struct {
	Now               *time.Time
	ID                uuid.UUID
	MaxFailedAttempts int32
}

type UseOAuthFlowParams

type UseOAuthFlowParams struct {
	Now *time.Time
	ID  uuid.UUID
}

type UseRecoveryCodeParams

type UseRecoveryCodeParams struct {
	Now      *time.Time
	UserID   uuid.UUID
	CodeHash []byte
}

type UseTwoFactorChallengeParams

type UseTwoFactorChallengeParams struct {
	Now *time.Time
	ID  uuid.UUID
}

type UserHasOAuthProviderParams

type UserHasOAuthProviderParams struct {
	UserID   uuid.UUID
	Provider string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL