mysql

package
v1.3.6 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2020 License: Apache-2.0 Imports: 4 Imported by: 27

Documentation

Index

Constants

View Source
const (
	// DefaultLocation is the default location for MySQL connections.
	DefaultLocation = "America/New_York"
	// DefaultMySQLPort is the default port for MySQL connections.
	DefaultMySQLPort = 3306
)

Variables

View Source
var (
	// MaxOpenConns will be used to set a MySQL
	// drivers MaxOpenConns value.
	MaxOpenConns = 1
	// MaxIdleConns will be used to set a MySQL
	// drivers MaxIdleConns value.
	MaxIdleConns = 1
)

Functions

This section is empty.

Types

type Config

type Config struct {
	Pw              string `envconfig:"MYSQL_PW"`
	User            string `envconfig:"MYSQL_USER"`
	Port            int    `envconfig:"MYSQL_PORT"`
	DBName          string `envconfig:"MYSQL_DB_NAME"`
	Location        string `envconfig:"MYSQL_LOCATION"`
	Host            string `envconfig:"MYSQL_HOST_NAME"`
	ReadTimeout     string `envconfig:"MYSQL_READ_TIMEOUT"`
	WriteTimeout    string `envconfig:"MYSQL_WRITE_TIMEOUT"`
	AddtlDSNOptions string `envconfig:"MYSQL_ADDTL_DSN_OPTIONS"`
}

Config holds everything you need to connect and interact with a MySQL DB.

func LoadConfigFromEnv

func LoadConfigFromEnv() *Config

LoadConfigFromEnv will attempt to load a MySQL object from environment variables. If not populated, nil is returned.

func (*Config) DB

func (m *Config) DB() (*sql.DB, error)

DB will attempt to open a sql connection with the credentials and the current MySQLMaxOpenConns and MySQLMaxIdleConns values. Users must import a mysql driver in their main to use this.

func (*Config) String

func (m *Config) String() string

String will return the MySQL connection string.

Jump to

Keyboard shortcuts

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