sqlite

package
v0.1.0-alpha.1 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package sqlite provides a SQLite adapter for auth stores.

Index

Constants

This section is empty.

Variables

View Source
var ErrIncompatibleSchema = errors.New("sqlite: incompatible schema")

ErrIncompatibleSchema reports an existing auth schema that cannot safely be used by the SQLite adapter.

Functions

func DeleteData

func DeleteData(ctx context.Context, db *sql.DB) error

DeleteData deletes all auth adapter data while keeping the SQLite schema.

This is intentionally separate from Migrate so schema creation stays non-destructive unless callers explicitly choose to delete data.

func Migrate

func Migrate(ctx context.Context, db *sql.DB) error

Migrate applies pending SQLite migrations.

func Migrations

func Migrations() []migrate.Migration

Migrations returns the SQLite schema migrations for the auth adapter.

func Open

func Open(ctx context.Context, dsn string) (*sql.DB, error)

Open opens a SQLite database and verifies connectivity.

func ValidateSchema

func ValidateSchema(ctx context.Context, db *sql.DB) error

ValidateSchema verifies that existing auth tables and indexes are compatible with the SQLite adapter.

Types

type MigrationDriver

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

MigrationDriver implements migrate.Driver for SQLite.

func NewMigrationDriver

func NewMigrationDriver(db *sql.DB) *MigrationDriver

NewMigrationDriver creates a SQLite migration driver.

func (*MigrationDriver) Applied

Applied returns migrations already applied, keyed by version.

func (*MigrationDriver) Apply

func (d *MigrationDriver) Apply(ctx context.Context, migration migrate.Migration) error

Apply applies migration and records it atomically.

func (*MigrationDriver) EnsureSchema

func (d *MigrationDriver) EnsureSchema(ctx context.Context) error

EnsureSchema creates the migration metadata table if needed.

type Store

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

Store implements auth stores using SQLite.

func NewStore

func NewStore(db *sql.DB) *Store

NewStore creates a SQLite store backed by db.

func (*Store) CreateAPIKey

func (s *Store) CreateAPIKey(ctx context.Context, key auth.APIKey) error

CreateAPIKey stores API key metadata.

func (*Store) CreateAPIKeyWithAudit

func (s *Store) CreateAPIKeyWithAudit(ctx context.Context, key auth.APIKey, event auth.AuditEvent) error

CreateAPIKeyWithAudit stores API key metadata and its audit event atomically.

func (*Store) CreatePrincipal

func (s *Store) CreatePrincipal(ctx context.Context, principal auth.Principal) error

CreatePrincipal stores a user or group principal.

func (*Store) DeleteData

func (s *Store) DeleteData(ctx context.Context) error

DeleteData deletes all auth adapter data while keeping the SQLite schema.

func (*Store) GetAPIKeyByID

func (s *Store) GetAPIKeyByID(ctx context.Context, keyID string) (auth.APIKey, error)

GetAPIKeyByID returns API key metadata by ID.

func (*Store) GetAPIKeyByPrefix

func (s *Store) GetAPIKeyByPrefix(ctx context.Context, prefix string) (auth.APIKey, error)

GetAPIKeyByPrefix returns API key metadata by public prefix.

func (*Store) GetPrincipal

func (s *Store) GetPrincipal(ctx context.Context, principalType auth.PrincipalType, principalID string) (auth.Principal, error)

GetPrincipal returns a user or group principal.

func (*Store) ListAPIKeys

func (s *Store) ListAPIKeys(ctx context.Context, ownerType auth.PrincipalType, ownerID string, page auth.PageRequest) (auth.Page[auth.APIKey], error)

ListAPIKeys returns a page of keys for a principal.

func (*Store) RecordAuditEvent

func (s *Store) RecordAuditEvent(ctx context.Context, event auth.AuditEvent) error

RecordAuditEvent stores an audit event.

func (*Store) RevokeAPIKey

func (s *Store) RevokeAPIKey(ctx context.Context, keyID string, revokedAt time.Time) error

RevokeAPIKey marks an API key as revoked.

func (*Store) RevokeAPIKeyWithAudit

func (s *Store) RevokeAPIKeyWithAudit(ctx context.Context, keyID string, revokedAt time.Time, event auth.AuditEvent) (auth.APIKey, error)

RevokeAPIKeyWithAudit reads and revokes an API key, then stores its audit event atomically.

func (*Store) TouchAPIKey

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

TouchAPIKey records successful use.

Jump to

Keyboard shortcuts

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