db

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var MigrationsFS embed.FS

Functions

func ApplyMeteringMigrations

func ApplyMeteringMigrations(meteringDB *sql.DB) error

ApplyMeteringMigrations applies all metering_*.sql migrations from the embedded FS to the given database. Exported for use by testutil and other packages that need an in-memory metering schema for testing.

func ApplyStateMigrations

func ApplyStateMigrations(stateDB *sql.DB) error

ApplyStateMigrations applies all state_*.sql migrations from the embedded FS to the given database. It is exported so that testutil and other packages can bring up an in-memory SQLite database with the real schema.

func MeteringPath

func MeteringPath(dbPath string) string

MeteringPath returns the metering database path for a state database path.

Types

type Store

type Store struct {
	StateDB    *sql.DB
	MeteringDB *sql.DB
}

func Open

func Open(dbPath string) (*Store, error)

Open opens the state DB and a metering DB derived from it (<db>-metering.db).

func OpenWithMetering

func OpenWithMetering(dbPath, meteringPath string) (*Store, error)

OpenWithMetering is Open with an explicit metering DB path; empty means derived.

func (*Store) Close

func (s *Store) Close() error

func (*Store) RevokeOldest

func (s *Store) RevokeOldest(tenantID string) (string, error)

RevokeOldest finds the oldest (by created_at) non-revoked API key for the given tenant and revokes it. It returns the revoked key's ID, or ("", nil) if no keys exist to revoke.

func (*Store) RevokeOldestExpired

func (s *Store) RevokeOldestExpired(tenantID string) (string, error)

RevokeOldestExpired finds the oldest expired (but not yet revoked) API key for the given tenant and revokes it. It returns the revoked key's ID, or ("", nil) if there are no expired keys to revoke.

Jump to

Keyboard shortcuts

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