Documentation
¶
Index ¶
- type DB
- type Manager
- type MigrationManager
- type TestDBConfig
- type TestDBManager
- func (tm *TestDBManager) CleanupTestDB(t *testing.T)
- func (tm *TestDBManager) CreateTestDB(t *testing.T) *DB
- func (tm *TestDBManager) ExecuteSQL(t *testing.T, sql string, args ...interface{})
- func (tm *TestDBManager) GetTestDB(t *testing.T) *DB
- func (tm *TestDBManager) QueryRow(t *testing.T, sql string, args ...interface{}) *sql.Row
- func (tm *TestDBManager) RunMigrations(t *testing.T, migrationsPath string)
- func (tm *TestDBManager) TruncateAllTables(t *testing.T)
- type TxFunc
- type TxManager
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DB ¶
DB wraps the database connection with additional functionality
func NewConnection ¶
NewConnection creates a new database connection with proper configuration
func TestDBSetup ¶
TestDBSetup is a helper function for setting up test database in test suites
func TestDBSetupWithConfig ¶
func TestDBSetupWithConfig(t *testing.T, cfg TestDBConfig, migrationsPath string) (*DB, func())
TestDBSetupWithConfig is a helper function for setting up test database with custom config
func (*DB) WithTransaction ¶
WithTransaction executes a function within a database transaction If the function returns an error, the transaction is rolled back Otherwise, the transaction is committed
type Manager ¶
type Manager struct {
DB *DB
TxManager *TxManager
MigrationManager *MigrationManager
// contains filtered or unexported fields
}
Manager manages database connections, migrations, and transactions
func NewManager ¶
NewManager creates a new database manager with all components
type MigrationManager ¶
type MigrationManager struct {
// contains filtered or unexported fields
}
MigrationManager handles database migrations
func NewMigrationManager ¶
func NewMigrationManager(db *DB, logger *slog.Logger) *MigrationManager
NewMigrationManager creates a new migration manager
func (*MigrationManager) GetMigrationVersion ¶
func (mm *MigrationManager) GetMigrationVersion(ctx context.Context, migrationsPath string) (uint, bool, error)
GetMigrationVersion returns the current migration version
func (*MigrationManager) RollbackMigration ¶
func (mm *MigrationManager) RollbackMigration(ctx context.Context, migrationsPath string) error
RollbackMigration rolls back the last migration
func (*MigrationManager) RunMigrations ¶
func (mm *MigrationManager) RunMigrations(ctx context.Context, migrationsPath string) error
RunMigrations executes all pending database migrations
type TestDBConfig ¶
type TestDBConfig struct {
BaseURL string
TestDBName string
MaxOpenConns int
MaxIdleConns int
ConnMaxLifetime time.Duration
ConnMaxIdleTime time.Duration
}
TestDBConfig holds configuration for test database setup
func DefaultTestDBConfig ¶
func DefaultTestDBConfig() TestDBConfig
DefaultTestDBConfig returns default test database configuration
type TestDBManager ¶
type TestDBManager struct {
// contains filtered or unexported fields
}
TestDBManager manages test database lifecycle
func NewTestDBManager ¶
func NewTestDBManager(t *testing.T, cfg TestDBConfig) *TestDBManager
NewTestDBManager creates a new test database manager
func (*TestDBManager) CleanupTestDB ¶
func (tm *TestDBManager) CleanupTestDB(t *testing.T)
CleanupTestDB drops the test database and closes connections
func (*TestDBManager) CreateTestDB ¶
func (tm *TestDBManager) CreateTestDB(t *testing.T) *DB
CreateTestDB creates a new test database
func (*TestDBManager) ExecuteSQL ¶
func (tm *TestDBManager) ExecuteSQL(t *testing.T, sql string, args ...interface{})
ExecuteSQL executes arbitrary SQL on the test database (useful for test setup)
func (*TestDBManager) GetTestDB ¶
func (tm *TestDBManager) GetTestDB(t *testing.T) *DB
GetTestDB returns the test database connection (creates if not exists)
func (*TestDBManager) RunMigrations ¶
func (tm *TestDBManager) RunMigrations(t *testing.T, migrationsPath string)
RunMigrations runs migrations on the test database
func (*TestDBManager) TruncateAllTables ¶
func (tm *TestDBManager) TruncateAllTables(t *testing.T)
TruncateAllTables truncates all tables in the test database (useful for test cleanup)