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) CleanupRateLimits(ctx context.Context, before time.Time) (int, error)
- func (s *Store) Close() error
- func (s *Store) CountAttempt(ctx context.Context, key string, window time.Duration, now time.Time) (int, time.Time, error)
- func (s *Store) CreateAPIKey(ctx context.Context, k *store.APIKey) error
- func (s *Store) DB() *sql.DB
- func (s *Store) DeleteSessionsExcept(ctx context.Context, sessionID string) (int, error)
- func (s *Store) InsertRow(ctx context.Context, table string, columns []string, values []any) error
- func (s *Store) ListAPIKeys(ctx context.Context, userID string) ([]store.APIKey, error)
- func (s *Store) ListUsers(ctx context.Context, f store.UserListFilter) ([]store.User, string, error)
- func (s *Store) LockEnabledUsersWithRole(ctx context.Context, role string) ([]string, error)
- func (s *Store) Migrator() store.Migrator
- func (s *Store) OAuthStates() store.OAuthStateStore
- func (s *Store) RecoveryCodes() store.RecoveryCodeStore
- 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) Sessions() store.SessionStore
- func (s *Store) TOTP() store.TOTPStore
- func (s *Store) TableColumns(ctx context.Context, table string) ([]string, bool, 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) 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
}
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) CleanupRateLimits ¶ added in v0.3.0
CleanupRateLimits implements store.RateLimitCounter.
func (*Store) Close ¶
Close implements store.Store. The database handle stays open because the application owns it.
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) CreateAPIKey ¶ added in v0.3.0
CreateAPIKey implements store.APIKeyStore.
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) ListAPIKeys ¶ added in v0.3.0
ListAPIKeys implements store.APIKeyStore.
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) LockEnabledUsersWithRole ¶ added in v0.3.0
LockEnabledUsersWithRole implements store.UserAdminStore.
func (*Store) OAuthStates ¶
func (s *Store) OAuthStates() store.OAuthStateStore
OAuthStates implements store.Store.
func (*Store) RecoveryCodes ¶ added in v0.2.0
func (s *Store) RecoveryCodes() store.RecoveryCodeStore
RecoveryCodes implements store.Store.
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) Sessions ¶
func (s *Store) Sessions() store.SessionStore
Sessions implements store.Store.
func (*Store) TableColumns ¶ added in v0.3.0
TableColumns implements store.CatalogInspector.
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.