Documentation
¶
Overview ¶
Package connection handles the creation, management, and cleanup of database connections (both standard library `sql.DB` and `pgxpool.Pool`) for the isolated test database used by emberkit.
Index ¶
- func ClosePgxPool(poolPtr **pgxpool.Pool, dsn string, logger *zap.Logger) cleanup.Func
- func CloseTestDBConnection(dbPtr **sql.DB, dsn string, logger *zap.Logger) cleanup.Func
- func ConnectPools(ctx context.Context, config config.Config, testDBName string, ...) (*sql.DB, *pgxpool.Pool, string, error)
- func GetDBNameFromDSN(dsn string) string
- func GetFreePort(host string) (int, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ClosePgxPool ¶
ClosePgxPool returns a cleanup function suitable for use with `cleanup.Manager`. The returned function closes the provided `pgxpool.Pool`.
func CloseTestDBConnection ¶
CloseTestDBConnection returns a cleanup function suitable for use with `cleanup.Manager`. The returned function closes the provided `sql.DB` connection pool.
func ConnectPools ¶
func ConnectPools(ctx context.Context, config config.Config, testDBName string, logger *zap.Logger) (*sql.DB, *pgxpool.Pool, string, error)
ConnectPools establishes both a standard library `sql.DB` connection pool and a `pgxpool.Pool` connection pool to the specified test database.
It constructs the DSN based on the provided config and testDBName, attempts to connect and ping both pools, and returns the established pools along with the DSN used. If any step fails, it ensures previously opened resources are closed before returning an error.
func GetDBNameFromDSN ¶
GetDBNameFromDSN is a wrapper around dbNameViaDBURL for convenience, returning "unknown" on error.
func GetFreePort ¶
GetFreePort asks the kernel for a free open port that is ready to use. It binds to TCP port 0 on the specified host (defaulting to "127.0.0.1"), retrieves the assigned port, and then closes the listener.
Types ¶
This section is empty.