db

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIKeyLookupRow

type APIKeyLookupRow struct {
	ID         pgtype.UUID    `json:"id"`
	TenantID   pgtype.UUID    `json:"tenant_id"`
	Scopes     []string       `json:"scopes"`
	AllowedIps []netip.Prefix `json:"allowed_ips"`
}

type ActingHandoffParams

type ActingHandoffParams struct {
	OldHash []byte `json:"old_hash"`
	NewHash []byte `json:"new_hash"`
}

type AddMemberParams

type AddMemberParams struct {
	UserID pgtype.UUID `json:"user_id"`
	Role   string      `json:"role"`
}

type CreateAPIKeyParams

type CreateAPIKeyParams struct {
	Name       string             `json:"name"`
	Prefix     string             `json:"prefix"`
	KeyHash    []byte             `json:"key_hash"`
	Scopes     []string           `json:"scopes"`
	AllowedIps []netip.Prefix     `json:"allowed_ips"`
	ExpiresAt  pgtype.Timestamptz `json:"expires_at"`
}

type CreateAPIKeyRow

type CreateAPIKeyRow struct {
	ID         pgtype.UUID        `json:"id"`
	Name       string             `json:"name"`
	Prefix     string             `json:"prefix"`
	Scopes     []string           `json:"scopes"`
	AllowedIps []netip.Prefix     `json:"allowed_ips"`
	ExpiresAt  pgtype.Timestamptz `json:"expires_at"`
	LastUsedAt pgtype.Timestamptz `json:"last_used_at"`
	CreatedAt  pgtype.Timestamptz `json:"created_at"`
}

type CreateActingSessionParams

type CreateActingSessionParams struct {
	TokenHash []byte             `json:"token_hash"`
	UserID    pgtype.UUID        `json:"user_id"`
	ExpiresAt pgtype.Timestamptz `json:"expires_at"`
	CreatedIp *netip.Addr        `json:"created_ip"`
	UserAgent string             `json:"user_agent"`
	AdminID   pgtype.UUID        `json:"admin_id"`
	AdminName pgtype.Text        `json:"admin_name"`
}

type CreateEmailTokenParams

type CreateEmailTokenParams struct {
	TokenHash []byte             `json:"token_hash"`
	Purpose   string             `json:"purpose"`
	Email     string             `json:"email"`
	ExpiresAt pgtype.Timestamptz `json:"expires_at"`
}

type CreateInvitedUserParams

type CreateInvitedUserParams struct {
	Email        string `json:"email"`
	PasswordHash string `json:"password_hash"`
	Name         string `json:"name"`
}

type CreateSessionParams

type CreateSessionParams struct {
	TokenHash []byte             `json:"token_hash"`
	UserID    pgtype.UUID        `json:"user_id"`
	ExpiresAt pgtype.Timestamptz `json:"expires_at"`
	CreatedIp *netip.Addr        `json:"created_ip"`
	UserAgent string             `json:"user_agent"`
}

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 DistributionUsageSinceParams

type DistributionUsageSinceParams struct {
	Meter              string             `json:"meter"`
	DistributionPrefix string             `json:"distribution_prefix"`
	Since              pgtype.Timestamptz `json:"since"`
}

type EmailTokenLookupParams

type EmailTokenLookupParams struct {
	TokenHash []byte `json:"token_hash"`
	Purpose   string `json:"purpose"`
}

type EmailTokenLookupRow

type EmailTokenLookupRow struct {
	UserID pgtype.UUID `json:"user_id"`
	Email  string      `json:"email"`
}

type GetAPIKeyRow

type GetAPIKeyRow struct {
	ID         pgtype.UUID        `json:"id"`
	Name       string             `json:"name"`
	Prefix     string             `json:"prefix"`
	Scopes     []string           `json:"scopes"`
	AllowedIps []netip.Prefix     `json:"allowed_ips"`
	ExpiresAt  pgtype.Timestamptz `json:"expires_at"`
	LastUsedAt pgtype.Timestamptz `json:"last_used_at"`
	CreatedAt  pgtype.Timestamptz `json:"created_at"`
}

type GetTenantRow

type GetTenantRow struct {
	ID        pgtype.UUID        `json:"id"`
	Name      string             `json:"name"`
	CreatedAt pgtype.Timestamptz `json:"created_at"`
}

type GetUserAccountRow

type GetUserAccountRow struct {
	ID              pgtype.UUID        `json:"id"`
	Email           string             `json:"email"`
	Name            pgtype.Text        `json:"name"`
	Phone           pgtype.Text        `json:"phone"`
	Locale          string             `json:"locale"`
	Timezone        pgtype.Text        `json:"timezone"`
	EmailVerifiedAt pgtype.Timestamptz `json:"email_verified_at"`
	LastLoginAt     pgtype.Timestamptz `json:"last_login_at"`
	CreatedAt       pgtype.Timestamptz `json:"created_at"`
}

type GetUserRow

type GetUserRow struct {
	ID    pgtype.UUID `json:"id"`
	Email string      `json:"email"`
	Name  pgtype.Text `json:"name"`
}

type InsertSupportVisitParams

type InsertSupportVisitParams struct {
	UserID    pgtype.UUID        `json:"user_id"`
	AdminID   pgtype.UUID        `json:"admin_id"`
	AdminName string             `json:"admin_name"`
	Reason    string             `json:"reason"`
	ExpiresAt pgtype.Timestamptz `json:"expires_at"`
}

type InviteLookupRow

type InviteLookupRow struct {
	ID            pgtype.UUID `json:"id"`
	TenantID      pgtype.UUID `json:"tenant_id"`
	TenantName    string      `json:"tenant_name"`
	Email         string      `json:"email"`
	Role          string      `json:"role"`
	AccountExists bool        `json:"account_exists"`
}

type ListAPIKeysParams

type ListAPIKeysParams struct {
	Pattern string             `json:"pattern"`
	AfterAt pgtype.Timestamptz `json:"after_at"`
	AfterID pgtype.UUID        `json:"after_id"`
	Lim     int32              `json:"lim"`
}

type ListAPIKeysRow

type ListAPIKeysRow struct {
	ID         pgtype.UUID        `json:"id"`
	Name       string             `json:"name"`
	Prefix     string             `json:"prefix"`
	Scopes     []string           `json:"scopes"`
	AllowedIps []netip.Prefix     `json:"allowed_ips"`
	ExpiresAt  pgtype.Timestamptz `json:"expires_at"`
	LastUsedAt pgtype.Timestamptz `json:"last_used_at"`
	CreatedAt  pgtype.Timestamptz `json:"created_at"`
}

type ListInvitesParams

type ListInvitesParams struct {
	Pattern string             `json:"pattern"`
	AfterAt pgtype.Timestamptz `json:"after_at"`
	AfterID pgtype.UUID        `json:"after_id"`
	Lim     int32              `json:"lim"`
}

type ListInvitesRow

type ListInvitesRow struct {
	ID        pgtype.UUID        `json:"id"`
	Email     string             `json:"email"`
	Role      string             `json:"role"`
	CreatedAt pgtype.Timestamptz `json:"created_at"`
	ExpiresAt pgtype.Timestamptz `json:"expires_at"`
}

type ListMembersParams

type ListMembersParams struct {
	Pattern string             `json:"pattern"`
	AfterAt pgtype.Timestamptz `json:"after_at"`
	AfterID pgtype.UUID        `json:"after_id"`
	Lim     int32              `json:"lim"`
}

type ListMembersRow

type ListMembersRow struct {
	ID       pgtype.UUID        `json:"id"`
	Email    string             `json:"email"`
	Name     pgtype.Text        `json:"name"`
	Role     string             `json:"role"`
	JoinedAt pgtype.Timestamptz `json:"joined_at"`
}

type ListMySessionsRow

type ListMySessionsRow struct {
	TokenHash       []byte             `json:"token_hash"`
	CreatedAt       pgtype.Timestamptz `json:"created_at"`
	LastSeenAt      pgtype.Timestamptz `json:"last_seen_at"`
	Ip              string             `json:"ip"`
	UserAgent       string             `json:"user_agent"`
	ActingAdminName string             `json:"acting_admin_name"`
}

type LoginLookupRow

type LoginLookupRow struct {
	UserID       pgtype.UUID `json:"user_id"`
	PasswordHash string      `json:"password_hash"`
	TenantID     pgtype.UUID `json:"tenant_id"`
}

type MyTenantsRow

type MyTenantsRow struct {
	ID          pgtype.UUID        `json:"id"`
	Name        string             `json:"name"`
	Role        string             `json:"role"`
	SuspendedAt pgtype.Timestamptz `json:"suspended_at"`
	JoinedAt    pgtype.Timestamptz `json:"joined_at"`
}

type NoticeExpiringKeysRow

type NoticeExpiringKeysRow struct {
	ID        pgtype.UUID        `json:"id"`
	Name      string             `json:"name"`
	ExpiresAt pgtype.Timestamptz `json:"expires_at"`
}

type Queries

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

func New

func New(db DBTX) *Queries

func (*Queries) APIKeyLookup

func (q *Queries) APIKeyLookup(ctx context.Context, keyHash []byte) (APIKeyLookupRow, error)

func (*Queries) APIKeyUsed

func (q *Queries) APIKeyUsed(ctx context.Context, id pgtype.UUID) error

func (*Queries) ActingHandoff

func (q *Queries) ActingHandoff(ctx context.Context, arg ActingHandoffParams) (pgtype.Timestamptz, error)

Trades a support session's one-time code for a new token, once; no row when the code is unknown, used or older than two minutes.

func (*Queries) AddMember

func (q *Queries) AddMember(ctx context.Context, arg AddMemberParams) error

func (*Queries) CountAPIKeys

func (q *Queries) CountAPIKeys(ctx context.Context, pattern string) (int64, error)

func (*Queries) CountInvites

func (q *Queries) CountInvites(ctx context.Context, pattern string) (int64, error)

func (*Queries) CountMembers

func (q *Queries) CountMembers(ctx context.Context, pattern string) (int64, error)

func (*Queries) CountOwners

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

func (*Queries) CreateAPIKey

func (q *Queries) CreateAPIKey(ctx context.Context, arg CreateAPIKeyParams) (CreateAPIKeyRow, error)

func (*Queries) CreateActingSession

func (q *Queries) CreateActingSession(ctx context.Context, arg CreateActingSessionParams) error

A session an Ulka admin uses as the person, with the visit the workspace sees, in the tenant's scope.

func (*Queries) CreateEmailToken

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

func (*Queries) CreateInvitedUser

func (q *Queries) CreateInvitedUser(ctx context.Context, arg CreateInvitedUserParams) (pgtype.UUID, error)

func (*Queries) CreateSession

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

func (*Queries) CreateTenant

func (q *Queries) CreateTenant(ctx context.Context, name string) error

func (*Queries) DeleteAPIKey

func (q *Queries) DeleteAPIKey(ctx context.Context, id pgtype.UUID) (int64, error)

func (*Queries) DeleteAllSessions

func (q *Queries) DeleteAllSessions(ctx context.Context) error

func (*Queries) DeleteEmailTokens

func (q *Queries) DeleteEmailTokens(ctx context.Context, purpose string) error

func (*Queries) DeleteInvite

func (q *Queries) DeleteInvite(ctx context.Context, id pgtype.UUID) (int64, error)

func (*Queries) DeleteMemberSessions

func (q *Queries) DeleteMemberSessions(ctx context.Context, userID pgtype.UUID) error

func (*Queries) DeleteOtherSessions

func (q *Queries) DeleteOtherSessions(ctx context.Context, keep []byte) (int64, error)

func (*Queries) DeleteSession

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

func (*Queries) DistributionUsageSince

func (q *Queries) DistributionUsageSince(ctx context.Context, arg DistributionUsageSinceParams) (float64, error)

A distribution's traffic since a time, from the CDN meters (keyed distribution|host|country|hour).

func (*Queries) EmailTokenLookup

func (q *Queries) EmailTokenLookup(ctx context.Context, arg EmailTokenLookupParams) (EmailTokenLookupRow, error)

func (*Queries) EncodedMinutesThisMonth

func (q *Queries) EncodedMinutesThisMonth(ctx context.Context) (float64, error)

func (*Queries) GetAPIKey

func (q *Queries) GetAPIKey(ctx context.Context, id pgtype.UUID) (GetAPIKeyRow, error)

Searches the name and prefix. Newest first, continuing after the (after_at, after_id) row.

func (*Queries) GetLimits

func (q *Queries) GetLimits(ctx context.Context) ([]byte, error)

func (*Queries) GetTenant

func (q *Queries) GetTenant(ctx context.Context) (GetTenantRow, error)

func (*Queries) GetUser

func (q *Queries) GetUser(ctx context.Context, id pgtype.UUID) (GetUserRow, error)

func (*Queries) GetUserAccount

func (q *Queries) GetUserAccount(ctx context.Context) (GetUserAccountRow, error)

func (*Queries) GetUserPasswordHash

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

func (*Queries) InsertSupportVisit

func (q *Queries) InsertSupportVisit(ctx context.Context, arg InsertSupportVisitParams) error

func (*Queries) InviteLookup

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

func (*Queries) IsMemberEmail

func (q *Queries) IsMemberEmail(ctx context.Context, email string) (bool, error)

func (*Queries) ListAPIKeys

func (q *Queries) ListAPIKeys(ctx context.Context, arg ListAPIKeysParams) ([]ListAPIKeysRow, error)

func (*Queries) ListInvites

func (q *Queries) ListInvites(ctx context.Context, arg ListInvitesParams) ([]ListInvitesRow, error)

Searches the email. Newest first, continuing after the (after_at, after_id) row.

func (*Queries) ListMembers

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

Searches the email and name. Newest first, continuing after the (after_at, after_id) row.

func (*Queries) ListMySessions

func (q *Queries) ListMySessions(ctx context.Context) ([]ListMySessionsRow, error)

Where the caller is signed in, most recently used first.

func (*Queries) LoginBlocked

func (q *Queries) LoginBlocked(ctx context.Context, email string) (bool, error)

func (*Queries) LoginFailed

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

func (*Queries) LoginLookup

func (q *Queries) LoginLookup(ctx context.Context, email string) (LoginLookupRow, error)

func (*Queries) LoginSucceeded

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

func (*Queries) MarkEmailVerified

func (q *Queries) MarkEmailVerified(ctx context.Context, email string) (int64, error)

func (*Queries) MemberRole

func (q *Queries) MemberRole(ctx context.Context, userID pgtype.UUID) (string, error)

func (*Queries) MyTenants

func (q *Queries) MyTenants(ctx context.Context) ([]MyTenantsRow, error)

func (*Queries) NoticeExpiringKeys

func (q *Queries) NoticeExpiringKeys(ctx context.Context) ([]NoticeExpiringKeysRow, error)

func (*Queries) RecentEmailToken

func (q *Queries) RecentEmailToken(ctx context.Context, purpose string) (bool, error)

func (*Queries) RecentSupportVisits

func (q *Queries) RecentSupportVisits(ctx context.Context) ([]RecentSupportVisitsRow, error)

Visits in the last 7 days, newest first, with the person used.

func (*Queries) RecordUsage

func (q *Queries) RecordUsage(ctx context.Context, arg RecordUsageParams) error

func (*Queries) RemoveMember

func (q *Queries) RemoveMember(ctx context.Context, userID pgtype.UUID) (int64, error)

func (*Queries) RenameTenant

func (q *Queries) RenameTenant(ctx context.Context, name string) error

func (*Queries) RetentionCore

func (q *Queries) RetentionCore(ctx context.Context) ([]RetentionCoreRow, error)

func (*Queries) SessionLookup

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

func (*Queries) SessionSeen

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

func (*Queries) SetMemberRole

func (q *Queries) SetMemberRole(ctx context.Context, arg SetMemberRoleParams) (int64, error)

func (*Queries) SetUserEmail

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

func (*Queries) Signup

func (q *Queries) Signup(ctx context.Context, arg SignupParams) (SignupRow, error)

RLS applies the tenant filter from app.tenant_id. Tables a user also sees across tenants (tenants, tenant_members, users, sessions) need an explicit filter: with app.user_id set, RLS alone returns more than one tenant's rows.

func (*Queries) SwitchSessionTenant

func (q *Queries) SwitchSessionTenant(ctx context.Context, arg SwitchSessionTenantParams) (int64, error)

func (*Queries) UpdateUserContact

func (q *Queries) UpdateUserContact(ctx context.Context, arg UpdateUserContactParams) error

func (*Queries) UpdateUserName

func (q *Queries) UpdateUserName(ctx context.Context, name string) error

func (*Queries) UpdateUserPassword

func (q *Queries) UpdateUserPassword(ctx context.Context, passwordHash string) error

func (*Queries) UpsertInvite

func (q *Queries) UpsertInvite(ctx context.Context, arg UpsertInviteParams) (UpsertInviteRow, error)

func (*Queries) UsageByRegion

func (q *Queries) UsageByRegion(ctx context.Context, arg UsageByRegionParams) ([]UsageByRegionRow, error)

func (*Queries) UsageDaily

func (q *Queries) UsageDaily(ctx context.Context, arg UsageDailyParams) ([]UsageDailyRow, error)

func (*Queries) UsageTotals

func (q *Queries) UsageTotals(ctx context.Context, arg UsageTotalsParams) ([]UsageTotalsRow, error)

func (*Queries) UserIDByEmail

func (q *Queries) UserIDByEmail(ctx context.Context, email string) (pgtype.UUID, error)

func (*Queries) UserSignedIn

func (q *Queries) UserSignedIn(ctx context.Context, userID pgtype.UUID) error

func (*Queries) WithTx

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

type RecentSupportVisitsRow

type RecentSupportVisitsRow struct {
	ID        pgtype.UUID        `json:"id"`
	AdminName string             `json:"admin_name"`
	Reason    string             `json:"reason"`
	StartedAt pgtype.Timestamptz `json:"started_at"`
	ExpiresAt pgtype.Timestamptz `json:"expires_at"`
	Email     string             `json:"email"`
	UserName  string             `json:"user_name"`
}

type RecordUsageParams

type RecordUsageParams struct {
	Meter    string             `json:"meter"`
	Key      string             `json:"key"`
	At       pgtype.Timestamptz `json:"at"`
	Region   string             `json:"region"`
	Quantity pgtype.Numeric     `json:"quantity"`
}

type RetentionCoreRow

type RetentionCoreRow struct {
	Tbl     string `json:"tbl"`
	Deleted int64  `json:"deleted"`
}

type SessionLookupRow

type SessionLookupRow struct {
	UserID          pgtype.UUID        `json:"user_id"`
	TenantID        pgtype.UUID        `json:"tenant_id"`
	Role            string             `json:"role"`
	ActingAdminID   pgtype.UUID        `json:"acting_admin_id"`
	ActingAdminName string             `json:"acting_admin_name"`
	ExpiresAt       pgtype.Timestamptz `json:"expires_at"`
}

type SetMemberRoleParams

type SetMemberRoleParams struct {
	Role   string      `json:"role"`
	UserID pgtype.UUID `json:"user_id"`
}

type SignupParams

type SignupParams struct {
	Email        string `json:"email"`
	PasswordHash string `json:"password_hash"`
	TenantName   string `json:"tenant_name"`
	Name         string `json:"name"`
}

type SignupRow

type SignupRow struct {
	TenantID pgtype.UUID `json:"tenant_id"`
	UserID   pgtype.UUID `json:"user_id"`
}

type SwitchSessionTenantParams

type SwitchSessionTenantParams struct {
	TenantID  pgtype.UUID `json:"tenant_id"`
	TokenHash []byte      `json:"token_hash"`
}

type UpdateUserContactParams

type UpdateUserContactParams struct {
	Phone    pgtype.Text `json:"phone"`
	Locale   string      `json:"locale"`
	Timezone pgtype.Text `json:"timezone"`
}

type UpsertInviteParams

type UpsertInviteParams struct {
	Email     string             `json:"email"`
	Role      string             `json:"role"`
	TokenHash []byte             `json:"token_hash"`
	InvitedBy pgtype.UUID        `json:"invited_by"`
	ExpiresAt pgtype.Timestamptz `json:"expires_at"`
}

type UpsertInviteRow

type UpsertInviteRow struct {
	ID        pgtype.UUID        `json:"id"`
	Email     string             `json:"email"`
	Role      string             `json:"role"`
	CreatedAt pgtype.Timestamptz `json:"created_at"`
	ExpiresAt pgtype.Timestamptz `json:"expires_at"`
}

type UsageByRegionParams

type UsageByRegionParams struct {
	Since pgtype.Timestamptz `json:"since"`
	Until pgtype.Timestamptz `json:"until"`
}

type UsageByRegionRow

type UsageByRegionRow struct {
	Region   string         `json:"region"`
	Meter    string         `json:"meter"`
	Quantity pgtype.Numeric `json:"quantity"`
}

type UsageDailyParams

type UsageDailyParams struct {
	Since pgtype.Timestamptz `json:"since"`
	Until pgtype.Timestamptz `json:"until"`
}

type UsageDailyRow

type UsageDailyRow struct {
	Day      pgtype.Date    `json:"day"`
	Meter    string         `json:"meter"`
	Quantity pgtype.Numeric `json:"quantity"`
}

type UsageTotalsParams

type UsageTotalsParams struct {
	Since pgtype.Timestamptz `json:"since"`
	Until pgtype.Timestamptz `json:"until"`
}

type UsageTotalsRow

type UsageTotalsRow struct {
	Meter    string         `json:"meter"`
	Quantity pgtype.Numeric `json:"quantity"`
}

Jump to

Keyboard shortcuts

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