Categorygithub.com/velmie/x/svc/sqlconnection/mysql
modulepackage
0.1.0
Repository: https://github.com/velmie/x.git
Documentation: pkg.go.dev

# README

mysql

The package provides functionality to read DB configuration from environment variables and open an SQL connection

Read configuration from environment variables

import (
    "github.com/velmie/x/svc/sqlconnection/mysql"
)

func main() {
    cfg, err := mysql.ConfigFromEnv("PFX_")
}

For the example above, it reads the following environment variables:

NameMeaningRequiredDefaultExample
PFX_DB_HOSTDatabase connection hostYes127.0.0.1
PFX_DB_PORTDatabase connection portYes3306
PFX_DB_USERDatabase connection userYesroot
PFX_DB_PASSDatabase connection passwordYessecret
PFX_DB_NAMEDatabase connection hostYesdb_name
PFX_DB_MAX_OPEN_CONNECTIONSMax number of connectionsNo10
PFX_DB_MAX_IDLE_CONNECTIONSMax number of idle connectionsNo2
PFX_DB_CONNECTION_MAX_LIFETIMEMax lifetime of connectionsNo10m
PFX_DB_CONNECTION_MAX_IDLE_TIMEMax lifetime of idle connectionsNo5m
PFX_DB_UNSAFE_DISABLE_TLSDisable TLS connectionNofalsetrue
PFX_DB_TLS_CERT_PATHPath to a PEM certificateNo/file.pem

Open an SQL connection

import (
    "github.com/velmie/x/svc/sqlconnection/mysql"
)

func main() {
    db, err := mysql.NewConnection(cfg, logger)
}

Default Max lifetime of connections is 1h. Default Max lifetime of idle connections is 10m.

# Functions

No description provided by the author
NewConnection creates new database connection.

# Structs

No description provided by the author

# Interfaces

No description provided by the author