Documentation
¶
Overview ¶
Package repository implements data persistence for authentication and authorization entities.
Provides PostgreSQL and MySQL implementations with transaction support via database.GetTx(). PostgreSQL uses native UUID types, MySQL uses BINARY(16) types.
Index ¶
- type MySQLAuditLogRepository
- func (m *MySQLAuditLogRepository) Create(ctx context.Context, auditLog *authDomain.AuditLog) error
- func (m *MySQLAuditLogRepository) DeleteOlderThan(ctx context.Context, olderThan time.Time, dryRun bool) (int64, error)
- func (m *MySQLAuditLogRepository) List(ctx context.Context, offset, limit int, createdAtFrom, createdAtTo *time.Time) ([]*authDomain.AuditLog, error)
- type MySQLClientRepository
- func (m *MySQLClientRepository) Create(ctx context.Context, client *authDomain.Client) error
- func (m *MySQLClientRepository) Get(ctx context.Context, clientID uuid.UUID) (*authDomain.Client, error)
- func (m *MySQLClientRepository) List(ctx context.Context, offset, limit int) ([]*authDomain.Client, error)
- func (m *MySQLClientRepository) Update(ctx context.Context, client *authDomain.Client) error
- type MySQLTokenRepository
- func (m *MySQLTokenRepository) Create(ctx context.Context, token *authDomain.Token) error
- func (m *MySQLTokenRepository) Get(ctx context.Context, tokenID uuid.UUID) (*authDomain.Token, error)
- func (m *MySQLTokenRepository) GetByTokenHash(ctx context.Context, tokenHash string) (*authDomain.Token, error)
- func (m *MySQLTokenRepository) Update(ctx context.Context, token *authDomain.Token) error
- type PostgreSQLAuditLogRepository
- func (p *PostgreSQLAuditLogRepository) Create(ctx context.Context, auditLog *authDomain.AuditLog) error
- func (p *PostgreSQLAuditLogRepository) DeleteOlderThan(ctx context.Context, olderThan time.Time, dryRun bool) (int64, error)
- func (p *PostgreSQLAuditLogRepository) List(ctx context.Context, offset, limit int, createdAtFrom, createdAtTo *time.Time) ([]*authDomain.AuditLog, error)
- type PostgreSQLClientRepository
- func (p *PostgreSQLClientRepository) Create(ctx context.Context, client *authDomain.Client) error
- func (p *PostgreSQLClientRepository) Get(ctx context.Context, clientID uuid.UUID) (*authDomain.Client, error)
- func (p *PostgreSQLClientRepository) List(ctx context.Context, offset, limit int) ([]*authDomain.Client, error)
- func (p *PostgreSQLClientRepository) Update(ctx context.Context, client *authDomain.Client) error
- type PostgreSQLTokenRepository
- func (p *PostgreSQLTokenRepository) Create(ctx context.Context, token *authDomain.Token) error
- func (p *PostgreSQLTokenRepository) Get(ctx context.Context, tokenID uuid.UUID) (*authDomain.Token, error)
- func (p *PostgreSQLTokenRepository) GetByTokenHash(ctx context.Context, tokenHash string) (*authDomain.Token, error)
- func (p *PostgreSQLTokenRepository) Update(ctx context.Context, token *authDomain.Token) error
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. Returns an error if UUID/metadata marshaling or database insertion fails.
func (*MySQLAuditLogRepository) DeleteOlderThan ¶ added in v0.2.0
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) List ¶
func (m *MySQLAuditLogRepository) List( ctx context.Context, offset, limit int, createdAtFrom, createdAtTo *time.Time, ) ([]*authDomain.AuditLog, error)
List retrieves audit logs ordered by created_at descending (newest first) with pagination and optional time-based filtering. Accepts createdAtFrom and createdAtTo as optional filters (nil means no filter). Both boundaries are inclusive (>= and <=). 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.
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 ¶
func (m *MySQLClientRepository) Get(ctx context.Context, clientID uuid.UUID) (*authDomain.Client, error)
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) List ¶
func (m *MySQLClientRepository) List( ctx context.Context, offset, limit int, ) ([]*authDomain.Client, error)
List retrieves clients ordered by ID descending with pagination support using BINARY(16) for UUIDs. Uses transaction support via database.GetTx(). Returns empty slice if no clients found, or an error if UUID/policy unmarshaling or database query fails.
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.
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 ¶
func (m *MySQLTokenRepository) Get(ctx context.Context, tokenID uuid.UUID) (*authDomain.Token, error)
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) 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.
type PostgreSQLAuditLogRepository ¶
type PostgreSQLAuditLogRepository struct {
// contains filtered or unexported fields
}
PostgreSQLAuditLogRepository implements AuditLog persistence for PostgreSQL. Uses native UUID types with transaction support via database.GetTx().
func NewPostgreSQLAuditLogRepository ¶
func NewPostgreSQLAuditLogRepository(db *sql.DB) *PostgreSQLAuditLogRepository
NewPostgreSQLAuditLogRepository creates a new PostgreSQL AuditLog repository.
func (*PostgreSQLAuditLogRepository) Create ¶
func (p *PostgreSQLAuditLogRepository) Create(ctx context.Context, auditLog *authDomain.AuditLog) error
Create inserts a new AuditLog into the PostgreSQL database. Uses transaction support via database.GetTx(). Handles nil metadata as database NULL. Returns an error if metadata marshaling or database insertion fails.
func (*PostgreSQLAuditLogRepository) DeleteOlderThan ¶ added in v0.2.0
func (p *PostgreSQLAuditLogRepository) 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 (*PostgreSQLAuditLogRepository) List ¶
func (p *PostgreSQLAuditLogRepository) List( ctx context.Context, offset, limit int, createdAtFrom, createdAtTo *time.Time, ) ([]*authDomain.AuditLog, error)
List retrieves audit logs ordered by created_at descending (newest first) with pagination and optional time-based filtering. Accepts createdAtFrom and createdAtTo as optional filters (nil means no filter). Both boundaries are inclusive (>= and <=). 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.
type PostgreSQLClientRepository ¶
type PostgreSQLClientRepository struct {
// contains filtered or unexported fields
}
PostgreSQLClientRepository implements Client persistence for PostgreSQL. Uses native UUID types with transaction support via database.GetTx().
func NewPostgreSQLClientRepository ¶
func NewPostgreSQLClientRepository(db *sql.DB) *PostgreSQLClientRepository
NewPostgreSQLClientRepository creates a new PostgreSQL Client repository.
func (*PostgreSQLClientRepository) Create ¶
func (p *PostgreSQLClientRepository) Create(ctx context.Context, client *authDomain.Client) error
Create inserts a new Client into the PostgreSQL database. Uses transaction support via database.GetTx(). Returns an error if policy marshaling or database insertion fails.
func (*PostgreSQLClientRepository) Get ¶
func (p *PostgreSQLClientRepository) Get( ctx context.Context, clientID uuid.UUID, ) (*authDomain.Client, error)
Get retrieves a Client by ID from the PostgreSQL database. Uses transaction support via database.GetTx(). Returns ErrClientNotFound if the client doesn't exist, or an error if policy unmarshaling or database query fails.
func (*PostgreSQLClientRepository) List ¶
func (p *PostgreSQLClientRepository) List( ctx context.Context, offset, limit int, ) ([]*authDomain.Client, error)
List retrieves clients ordered by ID descending with pagination support. Uses transaction support via database.GetTx(). Returns empty slice if no clients found, or an error if policy unmarshaling or database query fails.
func (*PostgreSQLClientRepository) Update ¶
func (p *PostgreSQLClientRepository) Update(ctx context.Context, client *authDomain.Client) error
Update modifies an existing Client in the PostgreSQL database. Uses transaction support via database.GetTx(). Returns an error if policy marshaling or database update fails.
type PostgreSQLTokenRepository ¶
type PostgreSQLTokenRepository struct {
// contains filtered or unexported fields
}
PostgreSQLTokenRepository implements Token persistence for PostgreSQL. Uses native UUID types with transaction support via database.GetTx().
func NewPostgreSQLTokenRepository ¶
func NewPostgreSQLTokenRepository(db *sql.DB) *PostgreSQLTokenRepository
NewPostgreSQLTokenRepository creates a new PostgreSQL Token repository.
func (*PostgreSQLTokenRepository) Create ¶
func (p *PostgreSQLTokenRepository) Create(ctx context.Context, token *authDomain.Token) error
Create inserts a new Token into the PostgreSQL database. Uses transaction support via database.GetTx(). Returns an error if database insertion fails.
func (*PostgreSQLTokenRepository) Get ¶
func (p *PostgreSQLTokenRepository) Get(ctx context.Context, tokenID uuid.UUID) (*authDomain.Token, error)
Get retrieves a Token by ID from the PostgreSQL database. Uses transaction support via database.GetTx(). Returns ErrTokenNotFound if the token doesn't exist, or an error if database query fails.
func (*PostgreSQLTokenRepository) GetByTokenHash ¶
func (p *PostgreSQLTokenRepository) GetByTokenHash( ctx context.Context, tokenHash string, ) (*authDomain.Token, error)
GetByTokenHash retrieves a Token by token hash from the PostgreSQL database. Uses transaction support via database.GetTx(). Returns ErrTokenNotFound if the token doesn't exist, or an error if database query fails.
func (*PostgreSQLTokenRepository) Update ¶
func (p *PostgreSQLTokenRepository) Update(ctx context.Context, token *authDomain.Token) error
Update modifies an existing Token in the PostgreSQL database. Uses transaction support via database.GetTx(). Returns an error if database update fails.