db

package
v0.3.1 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

New returns a DI-injectable constructor for Store.

Types

type Store

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

Store is a database-backed token store. It delegates to sqlc-generated queries and selects the correct dialect adapter at init time.

func (*Store) ConsumeTokenByHash

func (s *Store) ConsumeTokenByHash(ctx context.Context, tokenHash string) (*TokenRecord, error)

ConsumeTokenByHash atomically fetches and deletes a token by its hash, returning the record of the deleted row. Returns (nil, nil) if the token does not exist or was consumed concurrently by another caller.

func (*Store) DeleteExpiredTokens

func (s *Store) DeleteExpiredTokens(ctx context.Context, before time.Time) (int64, error)

DeleteExpiredTokens deletes tokens that expired before the given time.

func (*Store) DeleteTokenByHash

func (s *Store) DeleteTokenByHash(ctx context.Context, tokenHash string) (int64, error)

DeleteTokenByHash deletes a token by its hash and returns rows affected.

func (*Store) DeleteTokensBySubjectPurpose

func (s *Store) DeleteTokensBySubjectPurpose(ctx context.Context, subject, purpose string) error

DeleteTokensBySubjectPurpose deletes all tokens for a subject with a given purpose.

func (*Store) Init

func (s *Store) Init(serviceName string) error

Init selects the correct sqlc adapter and registers migrations.

func (*Store) InsertToken

func (s *Store) InsertToken(ctx context.Context, id, subject, tokenHash, purpose string, createdAt, expiresAt time.Time) error

InsertToken stores a new token record.

type TokenRecord

type TokenRecord struct {
	ExpiresAt time.Time
	ID        string
	Subject   string
	Purpose   string
}

TokenRecord holds the data returned when looking up a token.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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