sqlstore

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2026 License: MIT Imports: 10 Imported by: 0

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

View Source
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 New

func New(db *sql.DB, d Dialect) *Store

New returns a store over db.

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

func (s *Store) APIKeyByID(ctx context.Context, id string) (*store.APIKey, error)

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

func (s *Store) CleanupRateLimits(ctx context.Context, before time.Time) (int, error)

CleanupRateLimits implements store.RateLimitCounter.

func (*Store) Close

func (s *Store) Close() error

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

func (s *Store) CreateAPIKey(ctx context.Context, k *store.APIKey) error

CreateAPIKey implements store.APIKeyStore.

func (*Store) DB

func (s *Store) DB() *sql.DB

DB returns the underlying handle. It is owned by the application.

func (*Store) DeleteSessionsExcept added in v0.3.0

func (s *Store) DeleteSessionsExcept(ctx context.Context, sessionID string) (int, error)

DeleteSessionsExcept implements store.SessionRevoker. One statement finds the owner and removes the other sessions, so no read and no lock is needed.

func (*Store) InsertRow added in v0.3.0

func (s *Store) InsertRow(ctx context.Context, table string, columns []string, values []any) error

InsertRow implements store.RowWriter.

func (*Store) ListAPIKeys added in v0.3.0

func (s *Store) ListAPIKeys(ctx context.Context, userID string) ([]store.APIKey, error)

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

func (s *Store) LockEnabledUsersWithRole(ctx context.Context, role string) ([]string, error)

LockEnabledUsersWithRole implements store.UserAdminStore.

func (*Store) Migrator

func (s *Store) Migrator() store.Migrator

Migrator implements store.Store.

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

func (s *Store) RevokeAPIKey(ctx context.Context, id, byUserID string, at time.Time) error

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) TOTP added in v0.2.0

func (s *Store) TOTP() store.TOTPStore

TOTP implements store.Store.

func (*Store) TableColumns added in v0.3.0

func (s *Store) TableColumns(ctx context.Context, table string) ([]string, bool, error)

TableColumns implements store.CatalogInspector.

func (*Store) Tokens

func (s *Store) Tokens() store.TokenStore

Tokens implements store.Store.

func (*Store) TouchAPIKey added in v0.3.0

func (s *Store) TouchAPIKey(ctx context.Context, id string, at time.Time) error

TouchAPIKey implements store.APIKeyStore.

func (*Store) Transaction

func (s *Store) Transaction(ctx context.Context, fn func(store.Store) error) error

Transaction implements store.Store. A nested call joins the running transaction instead of opening a second one.

func (*Store) UseSchema added in v0.3.0

func (s *Store) UseSchema(o schema.Options) error

UseSchema implements store.SchemaConfigurable. It sets the physical table names of the host.

func (*Store) Users

func (s *Store) Users() store.UserStore

Users implements store.Store.

Jump to

Keyboard shortcuts

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