connection

package
v0.2025.3 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2025 License: MIT Imports: 11 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClosePgxPool

func ClosePgxPool(poolPtr **pgxpool.Pool, dsn string, logger *zap.Logger) cleanup.Func

ClosePgxPool returns a cleanup function suitable for use with `cleanup.Manager`. The returned function closes the provided `pgxpool.Pool`.

func CloseTestDBConnection

func CloseTestDBConnection(dbPtr **sql.DB, dsn string, logger *zap.Logger) cleanup.Func

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

func GetDBNameFromDSN(dsn string) string

GetDBNameFromDSN is a wrapper around dbNameViaDBURL for convenience, returning "unknown" on error.

func GetFreePort

func GetFreePort(host string) (int, error)

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.

Jump to

Keyboard shortcuts

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