postgres

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2026 License: MIT Imports: 17 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package postgres provides a production-grade implementation of theauth.Storage backed by PostgreSQL through pgx and sqlc-generated query bindings.

Migrations live under migrations/ and are append-only: a renamed column ships as a new migration. Use the in-package New constructor with a pgxpool.Pool. See STABILITY.md for the rules that govern future schema and query changes.

Package postgres provides a Postgres-backed storage.Storage implementation built on top of sqlc-generated queries and pgx/v5.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Store

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

Store is the Postgres-backed storage adapter.

func New

func New(pool *pgxpool.Pool) *Store

New constructs a Store using the given pgxpool.Pool.

func (*Store) AddGroupMembers added in v0.7.0

func (s *Store) AddGroupMembers(ctx context.Context, groupID theauth.ULID, userIDs []theauth.ULID) error

func (*Store) ConfirmTOTPSecret added in v0.5.0

func (s *Store) ConfirmTOTPSecret(ctx context.Context, userID theauth.ULID, at time.Time) error
func (s *Store) ConsumeMagicLink(ctx context.Context, tokenHash []byte) (*theauth.MagicLink, error)

func (*Store) ConsumePasswordResetToken added in v0.2.0

func (s *Store) ConsumePasswordResetToken(ctx context.Context, tokenHash []byte) (*theauth.PasswordResetToken, error)

func (*Store) ConsumeRecoveryCode added in v0.5.0

func (s *Store) ConsumeRecoveryCode(ctx context.Context, userID theauth.ULID, code string, at time.Time) error

func (*Store) CountUsersWithPermissionInOrg added in v1.0.0

func (s *Store) CountUsersWithPermissionInOrg(ctx context.Context, orgID theauth.ULID, perm string) (int, error)
func (s *Store) CreateMagicLink(ctx context.Context, ml theauth.MagicLink) error

func (*Store) CreatePasswordResetToken added in v0.2.0

func (s *Store) CreatePasswordResetToken(ctx context.Context, t theauth.PasswordResetToken) error

func (*Store) CreateSession

func (s *Store) CreateSession(ctx context.Context, sess theauth.Session) (theauth.Session, error)

func (*Store) CreateSessionWithAuthLevel added in v0.5.0

func (s *Store) CreateSessionWithAuthLevel(ctx context.Context, sess theauth.Session) (theauth.Session, error)

func (*Store) CreateUser

func (s *Store) CreateUser(ctx context.Context, u theauth.User) (theauth.User, error)

func (*Store) DeleteGroup added in v0.7.0

func (s *Store) DeleteGroup(ctx context.Context, id theauth.ULID) error

func (*Store) DeleteOrganization added in v0.7.0

func (s *Store) DeleteOrganization(ctx context.Context, id theauth.ULID) error

func (*Store) DeleteOrganizationMember added in v0.7.0

func (s *Store) DeleteOrganizationMember(ctx context.Context, orgID, userID theauth.ULID) error

func (*Store) DeleteRole added in v1.0.0

func (s *Store) DeleteRole(ctx context.Context, id theauth.ULID) error

func (*Store) DeleteSAMLConnection added in v0.7.0

func (s *Store) DeleteSAMLConnection(ctx context.Context, id theauth.ULID) error

func (*Store) DeleteTOTPSecret added in v0.5.0

func (s *Store) DeleteTOTPSecret(ctx context.Context, userID theauth.ULID) error

func (*Store) DeleteWebAuthnCredential added in v0.5.0

func (s *Store) DeleteWebAuthnCredential(ctx context.Context, id theauth.ULID, userID theauth.ULID) error

func (*Store) GrantUserRole added in v1.0.0

func (s *Store) GrantUserRole(ctx context.Context, ur theauth.UserRole) error

func (*Store) GroupByExternalIDInOrg added in v0.7.0

func (s *Store) GroupByExternalIDInOrg(ctx context.Context, orgID theauth.ULID, externalID string) (*theauth.Group, error)

func (*Store) GroupByID added in v0.7.0

func (s *Store) GroupByID(ctx context.Context, id theauth.ULID) (*theauth.Group, error)

func (*Store) GroupMembers added in v0.7.0

func (s *Store) GroupMembers(ctx context.Context, groupID theauth.ULID) ([]theauth.ULID, error)

func (*Store) InsertAuditEvents added in v1.0.0

func (s *Store) InsertAuditEvents(ctx context.Context, events []theauth.AuditEvent) error

func (*Store) InsertGroup added in v0.7.0

func (s *Store) InsertGroup(ctx context.Context, g theauth.Group) (theauth.Group, error)

func (*Store) InsertOrganization added in v0.7.0

func (s *Store) InsertOrganization(ctx context.Context, o theauth.Organization) (theauth.Organization, error)

func (*Store) InsertPermission added in v1.0.0

func (s *Store) InsertPermission(ctx context.Context, p theauth.Permission) (theauth.Permission, error)

func (*Store) InsertRecoveryCodes added in v0.5.0

func (s *Store) InsertRecoveryCodes(ctx context.Context, codes []theauth.RecoveryCode) error

func (*Store) InsertRole added in v1.0.0

func (s *Store) InsertRole(ctx context.Context, r theauth.Role) (theauth.Role, error)

func (*Store) InsertSAMLConnection added in v0.7.0

func (s *Store) InsertSAMLConnection(ctx context.Context, c theauth.SAMLConnection) (theauth.SAMLConnection, error)

func (*Store) InsertSCIMToken added in v0.7.0

func (s *Store) InsertSCIMToken(ctx context.Context, t theauth.SCIMToken) (theauth.SCIMToken, error)

func (*Store) InsertWebAuthnCredential added in v0.5.0

func (s *Store) InsertWebAuthnCredential(ctx context.Context, c theauth.WebAuthnCredential) (theauth.WebAuthnCredential, error)

func (*Store) ListGroupsByOrganization added in v0.7.0

func (s *Store) ListGroupsByOrganization(ctx context.Context, orgID theauth.ULID, offset, limit int, filter theauth.SCIMGroupFilter) ([]theauth.Group, int, error)

func (*Store) ListPermissions added in v1.0.0

func (s *Store) ListPermissions(ctx context.Context) ([]theauth.Permission, error)

func (*Store) ListUsersByOrganization added in v0.7.0

func (s *Store) ListUsersByOrganization(ctx context.Context, orgID theauth.ULID, offset, limit int, filter theauth.SCIMUserFilter) ([]theauth.User, int, error)

func (*Store) MarkEmailVerified

func (s *Store) MarkEmailVerified(ctx context.Context, userID theauth.ULID) error

func (*Store) OAuthAccountByProviderUserID added in v0.3.0

func (s *Store) OAuthAccountByProviderUserID(ctx context.Context, provider, providerUserID string) (*theauth.OAuthAccount, error)

func (*Store) OrganizationByID added in v0.7.0

func (s *Store) OrganizationByID(ctx context.Context, id theauth.ULID) (*theauth.Organization, error)

func (*Store) OrganizationBySlug added in v0.7.0

func (s *Store) OrganizationBySlug(ctx context.Context, slug string) (*theauth.Organization, error)

func (*Store) OrganizationMemberRole added in v0.7.0

func (s *Store) OrganizationMemberRole(ctx context.Context, orgID, userID theauth.ULID) (string, error)

func (*Store) OrganizationMembersByOrg added in v0.7.0

func (s *Store) OrganizationMembersByOrg(ctx context.Context, orgID theauth.ULID) ([]theauth.OrganizationMember, error)

func (*Store) OrganizationsByUser added in v0.7.0

func (s *Store) OrganizationsByUser(ctx context.Context, userID theauth.ULID) ([]theauth.Organization, error)

func (*Store) PermissionByName added in v1.0.0

func (s *Store) PermissionByName(ctx context.Context, name string) (*theauth.Permission, error)

func (*Store) PermissionsByRole added in v1.0.0

func (s *Store) PermissionsByRole(ctx context.Context, roleID theauth.ULID) ([]string, error)

func (*Store) PermissionsForUser added in v1.0.0

func (s *Store) PermissionsForUser(ctx context.Context, userID theauth.ULID, orgID *theauth.ULID) ([]string, error)

func (*Store) QueryAuditEvents added in v1.0.0

func (s *Store) QueryAuditEvents(ctx context.Context, q theauth.AuditQuery) ([]theauth.AuditEvent, string, error)

QueryAuditEvents is hand-built because the filter combinations vary too much for a fixed sqlc query. The query is keyset-paginated on (created_at DESC, id DESC) so it stays efficient as audit_events grows.

func (*Store) RemoveGroupMembers added in v0.7.0

func (s *Store) RemoveGroupMembers(ctx context.Context, groupID theauth.ULID, userIDs []theauth.ULID) error

func (*Store) RevokeSCIMTokenByID added in v0.7.0

func (s *Store) RevokeSCIMTokenByID(ctx context.Context, id theauth.ULID, at time.Time) error

func (*Store) RevokeSession

func (s *Store) RevokeSession(ctx context.Context, id theauth.ULID) error

func (*Store) RevokeUserRole added in v1.0.0

func (s *Store) RevokeUserRole(ctx context.Context, userID, roleID theauth.ULID) error

func (*Store) RevokeUserSessions

func (s *Store) RevokeUserSessions(ctx context.Context, userID theauth.ULID) error

func (*Store) RoleByID added in v1.0.0

func (s *Store) RoleByID(ctx context.Context, id theauth.ULID) (*theauth.Role, error)

func (*Store) RoleByOrgAndName added in v1.0.0

func (s *Store) RoleByOrgAndName(ctx context.Context, orgID *theauth.ULID, name string) (*theauth.Role, error)

func (*Store) RolesByOrganization added in v1.0.0

func (s *Store) RolesByOrganization(ctx context.Context, orgID *theauth.ULID) ([]theauth.Role, error)

func (*Store) RolesForUser added in v1.0.0

func (s *Store) RolesForUser(ctx context.Context, userID theauth.ULID, orgID *theauth.ULID) ([]theauth.Role, error)

func (*Store) SAMLConnectionByID added in v0.7.0

func (s *Store) SAMLConnectionByID(ctx context.Context, id theauth.ULID) (*theauth.SAMLConnection, error)

func (*Store) SAMLConnectionsByOrg added in v0.7.0

func (s *Store) SAMLConnectionsByOrg(ctx context.Context, orgID theauth.ULID) ([]theauth.SAMLConnection, error)

func (*Store) SAMLIdentityByConnectionAndNameID added in v0.7.0

func (s *Store) SAMLIdentityByConnectionAndNameID(ctx context.Context, connectionID theauth.ULID, nameID string) (*theauth.SAMLIdentity, error)

func (*Store) SCIMTokenByHash added in v0.7.0

func (s *Store) SCIMTokenByHash(ctx context.Context, hash []byte) (*theauth.SCIMToken, error)

func (*Store) SCIMTokensByOrg added in v0.7.0

func (s *Store) SCIMTokensByOrg(ctx context.Context, orgID theauth.ULID) ([]theauth.SCIMToken, error)

func (*Store) SessionByTokenHash

func (s *Store) SessionByTokenHash(ctx context.Context, hash []byte) (*theauth.Session, error)

func (*Store) SetGroupMembers added in v0.7.0

func (s *Store) SetGroupMembers(ctx context.Context, groupID theauth.ULID, userIDs []theauth.ULID) error

func (*Store) SetRolePermissions added in v1.0.0

func (s *Store) SetRolePermissions(ctx context.Context, roleID theauth.ULID, permissionIDs []theauth.ULID) error

func (*Store) SetSessionActiveOrganization added in v0.7.0

func (s *Store) SetSessionActiveOrganization(ctx context.Context, sessionID theauth.ULID, orgID *theauth.ULID) error

func (*Store) SetUserPassword added in v0.2.0

func (s *Store) SetUserPassword(ctx context.Context, userID theauth.ULID, passwordHash string) error

func (*Store) TOTPSecretByUserID added in v0.5.0

func (s *Store) TOTPSecretByUserID(ctx context.Context, userID theauth.ULID) (*theauth.TOTPSecret, error)

func (*Store) TouchSAMLIdentityLastLogin added in v0.7.0

func (s *Store) TouchSAMLIdentityLastLogin(ctx context.Context, id theauth.ULID, at time.Time) error

func (*Store) TouchSCIMTokenLastUsed added in v0.7.0

func (s *Store) TouchSCIMTokenLastUsed(ctx context.Context, id theauth.ULID, at time.Time) error

func (*Store) UpdateGroup added in v0.7.0

func (s *Store) UpdateGroup(ctx context.Context, g theauth.Group) error

func (*Store) UpdateOrganization added in v0.7.0

func (s *Store) UpdateOrganization(ctx context.Context, o theauth.Organization) error

func (*Store) UpdateRoleRow added in v1.0.0

func (s *Store) UpdateRoleRow(ctx context.Context, r theauth.Role) (theauth.Role, error)

func (*Store) UpdateSAMLConnectionRow added in v0.7.0

func (s *Store) UpdateSAMLConnectionRow(ctx context.Context, c theauth.SAMLConnection) error

func (*Store) UpdateSessionAuthLevel added in v0.5.0

func (s *Store) UpdateSessionAuthLevel(ctx context.Context, id theauth.ULID, level string) error

func (*Store) UpdateUserSCIM added in v0.7.0

func (s *Store) UpdateUserSCIM(ctx context.Context, u theauth.User) error

func (*Store) UpdateWebAuthnSignCount added in v0.5.0

func (s *Store) UpdateWebAuthnSignCount(ctx context.Context, credentialID []byte, newCount uint32, usedAt time.Time) error

UpdateWebAuthnSignCount executes the strictly-greater UPDATE; zero rows affected with the credential present means the supplied count was not strictly greater than the stored one, which is the WebAuthn replay signal. We disambiguate "no such credential" from "replay" via a follow up SELECT only when the UPDATE is a miss, to keep the happy path single round-trip.

func (*Store) UpsertOAuthAccount added in v0.3.0

func (s *Store) UpsertOAuthAccount(ctx context.Context, a theauth.OAuthAccount) (theauth.OAuthAccount, error)

func (*Store) UpsertOrganizationMember added in v0.7.0

func (s *Store) UpsertOrganizationMember(ctx context.Context, m theauth.OrganizationMember) error

func (*Store) UpsertPendingTOTPSecret added in v0.5.0

func (s *Store) UpsertPendingTOTPSecret(ctx context.Context, sec theauth.TOTPSecret) error

func (*Store) UpsertSAMLIdentity added in v0.7.0

func (s *Store) UpsertSAMLIdentity(ctx context.Context, i theauth.SAMLIdentity) (theauth.SAMLIdentity, error)

func (*Store) UserByEmail

func (s *Store) UserByEmail(ctx context.Context, email string) (*theauth.User, error)

func (*Store) UserByEmailWithPassword added in v0.2.0

func (s *Store) UserByEmailWithPassword(ctx context.Context, email string) (*theauth.User, string, error)

func (*Store) UserByExternalIDInOrg added in v0.7.0

func (s *Store) UserByExternalIDInOrg(ctx context.Context, orgID theauth.ULID, externalID string) (*theauth.User, error)

func (*Store) UserByID

func (s *Store) UserByID(ctx context.Context, id theauth.ULID) (*theauth.User, error)

func (*Store) WebAuthnCredentialByCredentialID added in v0.5.0

func (s *Store) WebAuthnCredentialByCredentialID(ctx context.Context, credentialID []byte) (*theauth.WebAuthnCredential, error)

func (*Store) WebAuthnCredentialsByUserID added in v0.5.0

func (s *Store) WebAuthnCredentialsByUserID(ctx context.Context, userID theauth.ULID) ([]theauth.WebAuthnCredential, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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