db

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

func Connect(driver, dsn string) (*sql.DB, error)

Connect opens a new database connection using the given driver name and DSN (Data Source Name). It pings the database to verify the connection is valid before returning.

Returns an error if the connection could not be opened or pinged.

Types

type SQLDatabase

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

SQLDatabase wraps a standard sql.DB instance and provides lifecycle management for SQL database connections.

func NewSQLDatabase

func NewSQLDatabase(cfg *cfg.DBConfig) (*SQLDatabase, error)

NewSQLDatabase initializes and returns a new SQLDatabase instance using the provided configuration. It sets connection pool parameters such as maximum open/idle connections and connection lifetime.

Returns an error if the connection could not be established.

func (*SQLDatabase) Close

func (db *SQLDatabase) Close() error

Close closes the underlying database connection. It is safe to call Close multiple times; if the DB is already nil, it does nothing.

func (*SQLDatabase) DB added in v0.2.3

func (db *SQLDatabase) DB() *sql.DB

DB returns a copy of the raw db

func (*SQLDatabase) Ping

func (db *SQLDatabase) Ping() error

Ping verifies that the database connection is still alive. It is useful for health checks or readiness probes.

Jump to

Keyboard shortcuts

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