Documentation
¶
Overview ¶
Package sqlstore implements the Auth-All storage boundary over database/sql. One implementation serves every first-party SQL adapter. A Dialect carries the small set of engine-specific behaviors.
Index ¶
- Constants
- type Dialect
- type Store
- func (s *Store) APIKeyByHash(ctx context.Context, keyHash string) (*store.APIKey, *store.User, error)
- func (s *Store) APIKeyByID(ctx context.Context, id string) (*store.APIKey, error)
- func (s *Store) Accounts() store.AccountStore
- func (s *Store) ActiveOrganizationOf(ctx context.Context, sessionID string) (string, error)
- func (s *Store) AddTeamMember(ctx context.Context, teamID, userID string) error
- func (s *Store) CleanupRateLimits(ctx context.Context, before time.Time) (int, error)
- func (s *Store) ClearActiveOrganization(ctx context.Context, orgID, userID string) error
- func (s *Store) Close() error
- func (s *Store) ConsumeInvitation(ctx context.Context, tokenHash string, now time.Time) (*store.Invitation, error)
- func (s *Store) CountAttempt(ctx context.Context, key string, window time.Duration, now time.Time) (int, time.Time, error)
- func (s *Store) CountMembers(ctx context.Context, orgID string) (int, error)
- func (s *Store) CountPendingInvitations(ctx context.Context, orgID string, now time.Time) (int, error)
- func (s *Store) CreateAPIKey(ctx context.Context, k *store.APIKey) error
- func (s *Store) CreateCustomRole(ctx context.Context, r *store.CustomRole) error
- func (s *Store) CreateInvitation(ctx context.Context, i *store.Invitation) error
- func (s *Store) CreateMembership(ctx context.Context, m *store.Membership) error
- func (s *Store) CreateOrganization(ctx context.Context, o *store.Organization) error
- func (s *Store) CreateTeam(ctx context.Context, t *store.Team) error
- func (s *Store) CustomRoleByName(ctx context.Context, orgID, name string) (*store.CustomRole, error)
- func (s *Store) DB() *sql.DB
- func (s *Store) DeleteCustomRole(ctx context.Context, orgID, name string) error
- func (s *Store) DeleteMembership(ctx context.Context, orgID, userID string) error
- func (s *Store) DeleteOrganization(ctx context.Context, id string) error
- func (s *Store) DeleteRows(ctx context.Context, table, column string, value any) (int, error)
- func (s *Store) DeleteSessionsExcept(ctx context.Context, sessionID string) (int, error)
- func (s *Store) DeleteTeam(ctx context.Context, id string) error
- func (s *Store) InsertRow(ctx context.Context, table string, columns []string, values []any) error
- func (s *Store) InvitationByID(ctx context.Context, id string) (*store.Invitation, error)
- func (s *Store) InvitationByTokenHash(ctx context.Context, tokenHash string) (*store.Invitation, error)
- func (s *Store) ListAPIKeys(ctx context.Context, userID string) ([]store.APIKey, error)
- func (s *Store) ListCustomRoles(ctx context.Context, orgID string) ([]store.CustomRole, error)
- func (s *Store) ListInvitations(ctx context.Context, f store.InvitationFilter) ([]store.Invitation, string, error)
- func (s *Store) ListMembers(ctx context.Context, f store.MemberFilter) ([]store.Membership, string, error)
- func (s *Store) ListOrganizations(ctx context.Context, f store.OrganizationFilter) ([]store.Organization, string, error)
- func (s *Store) ListTeamMembers(ctx context.Context, teamID string) ([]string, error)
- func (s *Store) ListTeams(ctx context.Context, orgID string) ([]store.Team, error)
- func (s *Store) ListUsers(ctx context.Context, f store.UserListFilter) ([]store.User, string, error)
- func (s *Store) LockActiveMembersWithRole(ctx context.Context, orgID, role string) ([]string, error)
- func (s *Store) LockEnabledUsersWithRole(ctx context.Context, role string) ([]string, error)
- func (s *Store) MembershipOf(ctx context.Context, orgID, userID string) (*store.Membership, error)
- func (s *Store) MembershipsOfUser(ctx context.Context, userID string) ([]store.Membership, error)
- func (s *Store) Migrator() store.Migrator
- func (s *Store) OAuthStates() store.OAuthStateStore
- func (s *Store) OrganizationByID(ctx context.Context, id string) (*store.Organization, error)
- func (s *Store) OrganizationBySlug(ctx context.Context, slug string) (*store.Organization, error)
- func (s *Store) RecoveryCodes() store.RecoveryCodeStore
- func (s *Store) RemoveTeamMember(ctx context.Context, teamID, userID string) error
- func (s *Store) RevokeAPIKey(ctx context.Context, id, byUserID string, at time.Time) error
- func (s *Store) SessionWithUser(ctx context.Context, tokenHash string) (*store.Session, *store.User, error)
- func (s *Store) SessionWithUserAndMembership(ctx context.Context, tokenHash string) (*store.Session, *store.User, *store.Organization, *store.Membership, error)
- func (s *Store) Sessions() store.SessionStore
- func (s *Store) SetActiveOrganization(ctx context.Context, sessionID, orgID string) error
- func (s *Store) SetInvitationStatus(ctx context.Context, id, from, to string) error
- func (s *Store) TOTP() store.TOTPStore
- func (s *Store) TableColumns(ctx context.Context, table string) ([]string, bool, error)
- func (s *Store) TeamByID(ctx context.Context, id string) (*store.Team, error)
- func (s *Store) TeamsOfUser(ctx context.Context, orgID, userID string) ([]store.Team, error)
- func (s *Store) Tokens() store.TokenStore
- func (s *Store) TouchAPIKey(ctx context.Context, id string, at time.Time) error
- func (s *Store) Transaction(ctx context.Context, fn func(store.Store) error) error
- func (s *Store) UpdateMembership(ctx context.Context, m *store.Membership) error
- func (s *Store) UpdateOrganization(ctx context.Context, o *store.Organization) error
- func (s *Store) UseSchema(o schema.Options) error
- func (s *Store) Users() store.UserStore
Constants ¶
const SQLiteTimeLayout = "2006-01-02T15:04:05.000000000"
SQLiteTimeLayout is the fixed-width UTC layout used by text timestamp columns. The fixed width keeps lexicographic order equal to time order.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dialect ¶
type Dialect struct {
// Name is the schema dialect.
Name schema.Dialect
// NumberedPlaceholders selects $1 style placeholders instead of ?.
NumberedPlaceholders bool
// TextTime stores timestamps as fixed-width UTC text.
TextTime bool
// IsUniqueViolation reports whether err is a uniqueness constraint failure.
IsUniqueViolation func(err error) bool
// StringAgg returns the aggregate expression that joins the values of one
// column with a separator. PostgreSQL uses string_agg and SQLite uses
// group_concat.
StringAgg func(expr, separator string) string
}
Dialect carries the engine-specific behavior of one adapter.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store is the database/sql implementation of store.Store.
func (*Store) APIKeyByHash ¶ added in v0.3.0
func (s *Store) APIKeyByHash(ctx context.Context, keyHash string) (*store.APIKey, *store.User, error)
APIKeyByHash implements store.APIKeyStore. The join keeps the credential resolution at one round trip.
func (*Store) APIKeyByID ¶ added in v0.3.0
APIKeyByID implements store.APIKeyStore.
func (*Store) Accounts ¶
func (s *Store) Accounts() store.AccountStore
Accounts implements store.Store.
func (*Store) ActiveOrganizationOf ¶ added in v0.4.0
ActiveOrganizationOf implements store.ActiveOrganizationStore.
func (*Store) AddTeamMember ¶ added in v0.4.0
AddTeamMember implements store.TeamStore.
func (*Store) CleanupRateLimits ¶ added in v0.3.0
CleanupRateLimits implements store.RateLimitCounter.
func (*Store) ClearActiveOrganization ¶ added in v0.4.0
ClearActiveOrganization implements store.ActiveOrganizationStore.
func (*Store) Close ¶
Close implements store.Store. The database handle stays open because the application owns it.
func (*Store) ConsumeInvitation ¶ added in v0.4.0
func (s *Store) ConsumeInvitation(ctx context.Context, tokenHash string, now time.Time) (*store.Invitation, error)
ConsumeInvitation implements store.InvitationStore.
One conditional update changes the status, so two parallel acceptances of one invitation never both pass.
func (*Store) CountAttempt ¶ added in v0.3.0
func (s *Store) CountAttempt(ctx context.Context, key string, window time.Duration, now time.Time) (int, time.Time, error)
CountAttempt implements store.RateLimitCounter.
One statement counts the attempt, so two instances cannot both read the same count. The statement needs no lock, so it is safe behind a transaction pooler.
func (*Store) CountMembers ¶ added in v0.4.0
CountMembers implements store.MembershipStore.
func (*Store) CountPendingInvitations ¶ added in v0.4.0
func (s *Store) CountPendingInvitations(ctx context.Context, orgID string, now time.Time) (int, error)
CountPendingInvitations implements store.InvitationStore.
func (*Store) CreateAPIKey ¶ added in v0.3.0
CreateAPIKey implements store.APIKeyStore.
func (*Store) CreateCustomRole ¶ added in v0.4.0
CreateCustomRole implements store.CustomRoleStore.
func (*Store) CreateInvitation ¶ added in v0.4.0
CreateInvitation implements store.InvitationStore.
func (*Store) CreateMembership ¶ added in v0.4.0
CreateMembership implements store.MembershipStore.
func (*Store) CreateOrganization ¶ added in v0.4.0
CreateOrganization implements store.OrganizationStore.
func (*Store) CreateTeam ¶ added in v0.4.0
CreateTeam implements store.TeamStore.
func (*Store) CustomRoleByName ¶ added in v0.4.0
func (s *Store) CustomRoleByName(ctx context.Context, orgID, name string) (*store.CustomRole, error)
CustomRoleByName implements store.CustomRoleStore.
func (*Store) DeleteCustomRole ¶ added in v0.4.0
DeleteCustomRole implements store.CustomRoleStore.
func (*Store) DeleteMembership ¶ added in v0.4.0
DeleteMembership implements store.MembershipStore.
func (*Store) DeleteOrganization ¶ added in v0.4.0
DeleteOrganization implements store.OrganizationStore.
The statements remove every row that belongs to the organization, so no orphan survives on an engine that applies no foreign key.
func (*Store) DeleteRows ¶ added in v0.4.0
DeleteRows implements store.RowDeleter.
func (*Store) DeleteSessionsExcept ¶ added in v0.3.0
DeleteSessionsExcept implements store.SessionRevoker. One statement finds the owner and removes the other sessions, so no read and no lock is needed.
func (*Store) DeleteTeam ¶ added in v0.4.0
DeleteTeam implements store.TeamStore.
The team memberships go with the team. The organization memberships stay, because a team is a group inside one organization.
func (*Store) InvitationByID ¶ added in v0.4.0
InvitationByID implements store.InvitationStore.
func (*Store) InvitationByTokenHash ¶ added in v0.4.0
func (s *Store) InvitationByTokenHash(ctx context.Context, tokenHash string) (*store.Invitation, error)
InvitationByTokenHash implements store.InvitationStore.
func (*Store) ListAPIKeys ¶ added in v0.3.0
ListAPIKeys implements store.APIKeyStore.
func (*Store) ListCustomRoles ¶ added in v0.4.0
ListCustomRoles implements store.CustomRoleStore.
func (*Store) ListInvitations ¶ added in v0.4.0
func (s *Store) ListInvitations(ctx context.Context, f store.InvitationFilter) ([]store.Invitation, string, error)
ListInvitations implements store.InvitationStore.
func (*Store) ListMembers ¶ added in v0.4.0
func (s *Store) ListMembers(ctx context.Context, f store.MemberFilter) ([]store.Membership, string, error)
ListMembers implements store.MembershipStore.
The order is the user identifier, which is unique inside one organization.
func (*Store) ListOrganizations ¶ added in v0.4.0
func (s *Store) ListOrganizations(ctx context.Context, f store.OrganizationFilter) ([]store.Organization, string, error)
ListOrganizations implements store.OrganizationStore.
The order is the slug and then the identifier, so a page is stable while rows arrive and leave.
func (*Store) ListTeamMembers ¶ added in v0.4.0
ListTeamMembers implements store.TeamStore.
func (*Store) ListUsers ¶ added in v0.3.0
func (s *Store) ListUsers(ctx context.Context, f store.UserListFilter) ([]store.User, string, error)
ListUsers implements store.UserAdminStore.
The order is the normalized email and then the identifier, so two users with one address order the same way in every page.
func (*Store) LockActiveMembersWithRole ¶ added in v0.4.0
func (s *Store) LockActiveMembersWithRole(ctx context.Context, orgID, role string) ([]string, error)
LockActiveMembersWithRole implements store.MembershipStore.
func (*Store) LockEnabledUsersWithRole ¶ added in v0.3.0
LockEnabledUsersWithRole implements store.UserAdminStore.
func (*Store) MembershipOf ¶ added in v0.4.0
MembershipOf implements store.MembershipStore.
func (*Store) MembershipsOfUser ¶ added in v0.4.0
MembershipsOfUser implements store.MembershipStore.
func (*Store) OAuthStates ¶
func (s *Store) OAuthStates() store.OAuthStateStore
OAuthStates implements store.Store.
func (*Store) OrganizationByID ¶ added in v0.4.0
OrganizationByID implements store.OrganizationStore.
func (*Store) OrganizationBySlug ¶ added in v0.4.0
OrganizationBySlug implements store.OrganizationStore.
func (*Store) RecoveryCodes ¶ added in v0.2.0
func (s *Store) RecoveryCodes() store.RecoveryCodeStore
RecoveryCodes implements store.Store.
func (*Store) RemoveTeamMember ¶ added in v0.4.0
RemoveTeamMember implements store.TeamStore.
func (*Store) RevokeAPIKey ¶ added in v0.3.0
RevokeAPIKey implements store.APIKeyStore.
func (*Store) SessionWithUser ¶ added in v0.3.0
func (s *Store) SessionWithUser(ctx context.Context, tokenHash string) (*store.Session, *store.User, error)
SessionWithUser implements store.SessionUserReader. It joins the session row and the user row, so credential resolution costs one round trip.
func (*Store) SessionWithUserAndMembership ¶ added in v0.4.0
func (s *Store) SessionWithUserAndMembership(ctx context.Context, tokenHash string) ( *store.Session, *store.User, *store.Organization, *store.Membership, error)
SessionWithUserAndMembership implements store.SessionOrgReader.
One statement returns the session row, the user row, the organization row, and the membership row. A permission check therefore costs no extra round trip. The joins are left joins, so a session with no active organization returns the same row shape.
func (*Store) Sessions ¶
func (s *Store) Sessions() store.SessionStore
Sessions implements store.Store.
func (*Store) SetActiveOrganization ¶ added in v0.4.0
SetActiveOrganization implements store.ActiveOrganizationStore.
func (*Store) SetInvitationStatus ¶ added in v0.4.0
SetInvitationStatus implements store.InvitationStore.
func (*Store) TableColumns ¶ added in v0.3.0
TableColumns implements store.CatalogInspector.
func (*Store) TeamsOfUser ¶ added in v0.4.0
TeamsOfUser implements store.TeamStore.
func (*Store) TouchAPIKey ¶ added in v0.3.0
TouchAPIKey implements store.APIKeyStore.
func (*Store) Transaction ¶
Transaction implements store.Store. A nested call joins the running transaction instead of opening a second one.
func (*Store) UpdateMembership ¶ added in v0.4.0
UpdateMembership implements store.MembershipStore.
func (*Store) UpdateOrganization ¶ added in v0.4.0
UpdateOrganization implements store.OrganizationStore.