database

package
v0.0.0-...-c3d4352 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2025 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLinkingCodeRepository

func NewLinkingCodeRepository(dbConn *DB) interfaces.LinkingCodeRepository

NewLinkingCodeRepository creates a new linking code repository

func NewOTPRepository

func NewOTPRepository(database *DB, cryptoService interfaces.CryptoService) interfaces.OTPRepository

NewOTPRepository creates a new OTP repository

func NewUserRepository

func NewUserRepository(dbConn *DB) interfaces.UserRepository

NewUserRepository creates a new user repository

func NewWebAuthnCredentialRepository

func NewWebAuthnCredentialRepository(database *DB) interfaces.WebAuthnCredentialRepository

NewWebAuthnCredentialRepository creates a new WebAuthn credential repository

func RunMigrations

func RunMigrations(cfg *config.Config) error

RunMigrations is a convenience function to run migrations during application startup

Types

type DB

type DB struct {
	Pool *pgxpool.Pool
}

DB wraps the pgxpool.Pool with additional functionality

func NewDB

func NewDB(cfg *config.Config) (*DB, error)

NewDB creates a new database connection pool

func (*DB) Close

func (db *DB) Close()

Close closes the database connection pool

func (*DB) Health

func (db *DB) Health(ctx context.Context) (*HealthInfo, error)

Health returns database health information

func (*DB) Ping

func (db *DB) Ping(ctx context.Context) error

Ping tests the database connection

func (*DB) WithTransaction

func (db *DB) WithTransaction(ctx context.Context, fn func(tx pgx.Tx) error) error

WithTransaction executes a function within a database transaction

type HealthInfo

type HealthInfo struct {
	Status               string        `json:"status"`
	Message              string        `json:"message"`
	AcquiredConns        int           `json:"acquired_conns"`
	IdleConns            int           `json:"idle_conns"`
	MaxConns             int           `json:"max_conns"`
	TotalConns           int           `json:"total_conns"`
	NewConnsCount        int64         `json:"new_conns_count"`
	AcquireCount         int64         `json:"acquire_count"`
	AcquireDuration      time.Duration `json:"acquire_duration"`
	EmptyAcquireCount    int64         `json:"empty_acquire_count"`
	CanceledAcquireCount int64         `json:"canceled_acquire_count"`
}

HealthInfo contains database health information

type LinkingCodeRepository

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

LinkingCodeRepository implements the domain linking code repository interface

func (*LinkingCodeRepository) CleanupExpired

func (r *LinkingCodeRepository) CleanupExpired(ctx context.Context) error

CleanupExpired removes all expired linking codes

func (*LinkingCodeRepository) Create

func (r *LinkingCodeRepository) Create(ctx context.Context, linkingCode *entities.LinkingCode) error

Create creates a new linking code

func (*LinkingCodeRepository) Delete

func (r *LinkingCodeRepository) Delete(ctx context.Context, id uuid.UUID) error

Delete deletes a linking code

func (*LinkingCodeRepository) GetActiveByUserID

func (r *LinkingCodeRepository) GetActiveByUserID(ctx context.Context, userID uuid.UUID) ([]*entities.LinkingCode, error)

GetActiveByUserID retrieves all active (valid) linking codes for a user

func (*LinkingCodeRepository) GetByCode

GetByCode retrieves a linking code by its code

func (*LinkingCodeRepository) GetByUserID

func (r *LinkingCodeRepository) GetByUserID(ctx context.Context, userID uuid.UUID) ([]*entities.LinkingCode, error)

GetByUserID retrieves all linking codes for a user

func (*LinkingCodeRepository) Update

func (r *LinkingCodeRepository) Update(ctx context.Context, linkingCode *entities.LinkingCode) error

Update updates an existing linking code

type MigrationManager

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

MigrationManager handles database migrations

func NewMigrationManager

func NewMigrationManager(cfg *config.Config) (*MigrationManager, error)

NewMigrationManager creates a new migration manager

func (*MigrationManager) Close

func (m *MigrationManager) Close() error

Close closes the migration manager database connection

func (*MigrationManager) Create

func (m *MigrationManager) Create(name string) error

Create creates a new migration file

func (*MigrationManager) Down

func (m *MigrationManager) Down() error

Down rolls back migrations

func (*MigrationManager) Status

func (m *MigrationManager) Status() error

Status shows the migration status

func (*MigrationManager) Up

func (m *MigrationManager) Up() error

Up runs all pending migrations

func (*MigrationManager) Version

func (m *MigrationManager) Version() (int64, error)

Version shows the current migration version

type UserRepository

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

UserRepository implements the domain user repository interface

func (*UserRepository) Create

func (r *UserRepository) Create(ctx context.Context, user *entities.User) error

Create creates a new user

func (*UserRepository) Deactivate

func (r *UserRepository) Deactivate(ctx context.Context, userID uuid.UUID) error

Deactivate marks a user as inactive (soft delete)

func (*UserRepository) ExistsByEmail

func (r *UserRepository) ExistsByEmail(ctx context.Context, email string) (bool, error)

ExistsByEmail checks if a user exists by email

func (*UserRepository) ExistsByUsername

func (r *UserRepository) ExistsByUsername(ctx context.Context, username string) (bool, error)

ExistsByUsername checks if a user exists by username

func (*UserRepository) GetByEmail

func (r *UserRepository) GetByEmail(ctx context.Context, email string) (*entities.User, error)

GetByEmail retrieves a user by email

func (*UserRepository) GetByID

func (r *UserRepository) GetByID(ctx context.Context, id uuid.UUID) (*entities.User, error)

GetByID retrieves a user by ID

func (*UserRepository) GetByUsername

func (r *UserRepository) GetByUsername(ctx context.Context, username string) (*entities.User, error)

GetByUsername retrieves a user by username

func (*UserRepository) Update

func (r *UserRepository) Update(ctx context.Context, user *entities.User) error

Update updates an existing user

func (*UserRepository) UpdateLastLogin

func (r *UserRepository) UpdateLastLogin(ctx context.Context, userID uuid.UUID) error

UpdateLastLogin updates the user's last login timestamp

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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