mysql

package
v0.28.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MySQLAuditLogRepository

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

MySQLAuditLogRepository implements AuditLog persistence for MySQL. Uses BINARY(16) for UUID storage with transaction support via database.GetTx().

func NewMySQLAuditLogRepository

func NewMySQLAuditLogRepository(db *sql.DB) *MySQLAuditLogRepository

NewMySQLAuditLogRepository creates a new MySQL AuditLog repository.

func (*MySQLAuditLogRepository) Create

func (m *MySQLAuditLogRepository) Create(ctx context.Context, auditLog *authDomain.AuditLog) error

Create inserts a new AuditLog into the MySQL database using BINARY(16) for UUIDs. Uses transaction support via database.GetTx(). Handles nil metadata as database NULL. Includes cryptographic signature fields for tamper detection. Returns an error if UUID/metadata marshaling or database insertion fails.

func (*MySQLAuditLogRepository) DeleteOlderThan

func (m *MySQLAuditLogRepository) DeleteOlderThan(
	ctx context.Context,
	olderThan time.Time,
	dryRun bool,
) (int64, error)

DeleteOlderThan removes audit logs created before the specified timestamp. When dryRun is true, returns count via SELECT COUNT(*) without deletion. When false, executes DELETE and returns affected rows. Uses transaction support via database.GetTx(). All timestamps are expected in UTC.

func (*MySQLAuditLogRepository) Get

Get retrieves a single audit log by ID from the MySQL database. UUIDs are stored as BINARY(16) and must be marshaled/unmarshaled. Returns error if the audit log is not found or if database operation fails.

func (*MySQLAuditLogRepository) ListCursor added in v0.25.0

func (m *MySQLAuditLogRepository) ListCursor(
	ctx context.Context,
	afterID *uuid.UUID,
	limit int,
	createdAtFrom, createdAtTo *time.Time,
	clientID *uuid.UUID,
) ([]*authDomain.AuditLog, error)

ListCursor retrieves audit logs ordered by created_at descending (newest first) with cursor-based pagination and optional time-based filtering. If afterID is provided, returns logs with ID greater than afterID (UUIDv7 ordering). Accepts createdAtFrom and createdAtTo as optional filters (nil means no filter). Both boundaries are inclusive (>= and <=). Accepts clientID as an optional filter (nil means no filter). All timestamps are expected in UTC. Returns empty slice if no audit logs found. Handles NULL metadata gracefully by returning nil map for those entries. UUIDs are stored as BINARY(16) and must be unmarshaled. Limit is pre-validated (1-1000).

type MySQLClientRepository

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

MySQLClientRepository implements Client persistence for MySQL. Uses BINARY(16) for UUID storage with transaction support via database.GetTx().

func NewMySQLClientRepository

func NewMySQLClientRepository(db *sql.DB) *MySQLClientRepository

NewMySQLClientRepository creates a new MySQL Client repository.

func (*MySQLClientRepository) Create

func (m *MySQLClientRepository) Create(ctx context.Context, client *authDomain.Client) error

Create inserts a new Client into the MySQL database using BINARY(16) for UUIDs. Uses transaction support via database.GetTx(). Returns an error if UUID/policy marshaling or database insertion fails.

func (*MySQLClientRepository) Get

Get retrieves a Client by ID from the MySQL database using BINARY(16) for UUIDs. Uses transaction support via database.GetTx(). Returns ErrClientNotFound if the client doesn't exist, or an error if UUID/policy unmarshaling or database query fails.

func (*MySQLClientRepository) ListCursor added in v0.25.0

func (m *MySQLClientRepository) ListCursor(
	ctx context.Context,
	afterID *uuid.UUID,
	limit int,
) ([]*authDomain.Client, error)

ListCursor retrieves clients ordered by ID descending (newest first) with cursor-based pagination. If afterID is provided, returns clients with ID less than afterID (for DESC ordering). UUIDs are stored as BINARY(16) and require marshaling. Uses transaction support via database.GetTx(). Returns empty slice if no clients found, or an error if UUID/policy unmarshaling or database query fails. Limit is pre-validated (1-1000).

func (*MySQLClientRepository) Update

func (m *MySQLClientRepository) Update(ctx context.Context, client *authDomain.Client) error

Update modifies an existing Client in the MySQL database using BINARY(16) for UUIDs. Uses transaction support via database.GetTx(). Returns an error if UUID/policy marshaling or database update fails.

func (*MySQLClientRepository) UpdateLockState

func (m *MySQLClientRepository) UpdateLockState(
	ctx context.Context,
	clientID uuid.UUID,
	failedAttempts int,
	lockedUntil *time.Time,
) error

UpdateLockState atomically updates the failed attempt counter and lock expiry for a client.

type MySQLTokenRepository

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

MySQLTokenRepository implements Token persistence for MySQL. Uses BINARY(16) for UUIDs with transaction support via database.GetTx().

func NewMySQLTokenRepository

func NewMySQLTokenRepository(db *sql.DB) *MySQLTokenRepository

NewMySQLTokenRepository creates a new MySQL Token repository.

func (*MySQLTokenRepository) Create

func (m *MySQLTokenRepository) Create(ctx context.Context, token *authDomain.Token) error

Create inserts a new Token into the MySQL database using BINARY(16) for UUIDs. Uses transaction support via database.GetTx(). Returns an error if UUID marshaling or database insertion fails.

func (*MySQLTokenRepository) Get

Get retrieves a Token by ID from the MySQL database using BINARY(16) for UUIDs. Uses transaction support via database.GetTx(). Returns ErrTokenNotFound if the token doesn't exist, or an error if UUID unmarshaling or database query fails.

func (*MySQLTokenRepository) GetByTokenHash

func (m *MySQLTokenRepository) GetByTokenHash(
	ctx context.Context,
	tokenHash string,
) (*authDomain.Token, error)

GetByTokenHash retrieves a Token by token hash from the MySQL database using BINARY(16) for UUIDs. Uses transaction support via database.GetTx(). Returns ErrTokenNotFound if the token doesn't exist, or an error if UUID unmarshaling or database query fails.

func (*MySQLTokenRepository) PurgeExpiredAndRevoked added in v0.27.0

func (m *MySQLTokenRepository) PurgeExpiredAndRevoked(
	ctx context.Context,
	olderThan time.Time,
) (int64, error)

PurgeExpiredAndRevoked permanently deletes tokens that are either expired or revoked and were created before the specified timestamp. Returns the number of deleted tokens.

func (*MySQLTokenRepository) RevokeByClientID added in v0.27.0

func (m *MySQLTokenRepository) RevokeByClientID(ctx context.Context, clientID uuid.UUID) error

RevokeByClientID marks all active tokens for a specific client as revoked.

func (*MySQLTokenRepository) RevokeByTokenID added in v0.27.0

func (m *MySQLTokenRepository) RevokeByTokenID(ctx context.Context, tokenID uuid.UUID) error

RevokeByTokenID marks a specific token as revoked by setting its revoked_at timestamp.

func (*MySQLTokenRepository) Update

func (m *MySQLTokenRepository) Update(ctx context.Context, token *authDomain.Token) error

Update modifies an existing Token in the MySQL database using BINARY(16) for UUIDs. Uses transaction support via database.GetTx(). Returns an error if UUID marshaling or database update fails.

Jump to

Keyboard shortcuts

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