repository

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package repository implements data persistence for tokenization key and token management. Supports versioning, soft deletion, deterministic token lookups, and dual database support (PostgreSQL and MySQL).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MySQLTokenRepository

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

MySQLTokenRepository implements token persistence for MySQL databases.

func NewMySQLTokenRepository

func NewMySQLTokenRepository(db *sql.DB) *MySQLTokenRepository

NewMySQLTokenRepository creates a new MySQL token repository instance.

func (*MySQLTokenRepository) CountExpired

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

CountExpired counts tokens that expired before the specified timestamp without deleting them. Returns the count of matching tokens. Uses transaction support via database.GetTx(). All timestamps are expected in UTC.

func (*MySQLTokenRepository) Create

Create inserts a new token mapping into the MySQL database.

func (*MySQLTokenRepository) DeleteExpired

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

DeleteExpired deletes tokens that expired before the specified timestamp. Returns the number of deleted tokens. Uses transaction support via database.GetTx(). All timestamps are expected in UTC.

func (*MySQLTokenRepository) GetByToken

func (m *MySQLTokenRepository) GetByToken(
	ctx context.Context,
	tokenStr string,
) (*tokenizationDomain.Token, error)

GetByToken retrieves a token mapping by its token string.

func (*MySQLTokenRepository) GetByValueHash

func (m *MySQLTokenRepository) GetByValueHash(
	ctx context.Context,
	keyID uuid.UUID,
	valueHash string,
) (*tokenizationDomain.Token, error)

GetByValueHash retrieves a token by its value hash (for deterministic mode).

func (*MySQLTokenRepository) Revoke

func (m *MySQLTokenRepository) Revoke(ctx context.Context, tokenStr string) error

Revoke marks a token as revoked by setting its revoked_at timestamp.

type MySQLTokenizationKeyRepository

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

MySQLTokenizationKeyRepository implements tokenization key persistence for MySQL databases.

func NewMySQLTokenizationKeyRepository

func NewMySQLTokenizationKeyRepository(db *sql.DB) *MySQLTokenizationKeyRepository

NewMySQLTokenizationKeyRepository creates a new MySQL tokenization key repository instance.

func (*MySQLTokenizationKeyRepository) Create

Create inserts a new tokenization key into the MySQL database.

func (*MySQLTokenizationKeyRepository) Delete

Delete soft-deletes a tokenization key by setting its deleted_at timestamp.

func (*MySQLTokenizationKeyRepository) Get

Get retrieves a tokenization key by its ID.

func (*MySQLTokenizationKeyRepository) GetByName

GetByName retrieves the latest non-deleted version of a tokenization key by name.

func (*MySQLTokenizationKeyRepository) GetByNameAndVersion

func (m *MySQLTokenizationKeyRepository) GetByNameAndVersion(
	ctx context.Context,
	name string,
	version uint,
) (*tokenizationDomain.TokenizationKey, error)

GetByNameAndVersion retrieves a specific version of a tokenization key by name and version.

type PostgreSQLTokenRepository

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

PostgreSQLTokenRepository implements token persistence for PostgreSQL databases.

func NewPostgreSQLTokenRepository

func NewPostgreSQLTokenRepository(db *sql.DB) *PostgreSQLTokenRepository

NewPostgreSQLTokenRepository creates a new PostgreSQL token repository instance.

func (*PostgreSQLTokenRepository) CountExpired

func (p *PostgreSQLTokenRepository) CountExpired(ctx context.Context, olderThan time.Time) (int64, error)

CountExpired counts tokens that expired before the specified timestamp without deleting them. Returns the count of matching tokens. Uses transaction support via database.GetTx(). All timestamps are expected in UTC.

func (*PostgreSQLTokenRepository) Create

Create inserts a new token mapping into the PostgreSQL database.

func (*PostgreSQLTokenRepository) DeleteExpired

func (p *PostgreSQLTokenRepository) DeleteExpired(ctx context.Context, olderThan time.Time) (int64, error)

DeleteExpired deletes tokens that expired before the specified timestamp. Returns the number of deleted tokens. Uses transaction support via database.GetTx(). All timestamps are expected in UTC.

func (*PostgreSQLTokenRepository) GetByToken

func (p *PostgreSQLTokenRepository) GetByToken(
	ctx context.Context,
	tokenStr string,
) (*tokenizationDomain.Token, error)

GetByToken retrieves a token mapping by its token string.

func (*PostgreSQLTokenRepository) GetByValueHash

func (p *PostgreSQLTokenRepository) GetByValueHash(
	ctx context.Context,
	keyID uuid.UUID,
	valueHash string,
) (*tokenizationDomain.Token, error)

GetByValueHash retrieves a token by its value hash (for deterministic mode).

func (*PostgreSQLTokenRepository) Revoke

func (p *PostgreSQLTokenRepository) Revoke(ctx context.Context, tokenStr string) error

Revoke marks a token as revoked by setting its revoked_at timestamp.

type PostgreSQLTokenizationKeyRepository

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

PostgreSQLTokenizationKeyRepository implements tokenization key persistence for PostgreSQL databases.

func NewPostgreSQLTokenizationKeyRepository

func NewPostgreSQLTokenizationKeyRepository(db *sql.DB) *PostgreSQLTokenizationKeyRepository

NewPostgreSQLTokenizationKeyRepository creates a new PostgreSQL tokenization key repository instance.

func (*PostgreSQLTokenizationKeyRepository) Create

Create inserts a new tokenization key into the PostgreSQL database.

func (*PostgreSQLTokenizationKeyRepository) Delete

Delete soft-deletes a tokenization key by setting its deleted_at timestamp.

func (*PostgreSQLTokenizationKeyRepository) Get

Get retrieves a tokenization key by its ID.

func (*PostgreSQLTokenizationKeyRepository) GetByName

GetByName retrieves the latest non-deleted version of a tokenization key by name.

func (*PostgreSQLTokenizationKeyRepository) GetByNameAndVersion

func (p *PostgreSQLTokenizationKeyRepository) GetByNameAndVersion(
	ctx context.Context,
	name string,
	version uint,
) (*tokenizationDomain.TokenizationKey, error)

GetByNameAndVersion retrieves a specific version of a tokenization key by name and version.

Jump to

Keyboard shortcuts

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