connector

package
v1.1.9 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: BSD-2-Clause Imports: 7 Imported by: 3

Documentation

Overview

Package connector is used to specify how to connect to MySQL. Then get a sql.*DB from it which is returned to the app.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config added in v1.1.0

type Config struct {
	Host           *string // the host to connect to
	Socket         *string // the unix socket to connect with
	Port           *int    // the port to connect to
	User           *string // the user to connect with
	Password       *string // the password to use
	DefaultsFile   *string // name of the defaults file to use
	UseEnvironment *bool   // use the environment to set connection settings?
}

Config holds various command line flags related to connecting to the database

type ConnectMethod added in v1.0.11

type ConnectMethod int

ConnectMethod indicates how we want to connect to MySQL

const (

	// ConnectByDefaultsFile indicates we want to connect using a MySQL defaults file
	ConnectByDefaultsFile ConnectMethod = iota
	// ConnectByConfig indicates we want to connect by various components (fields)
	ConnectByConfig
	// ConnectByEnvironment indicates we want to connect by using MYSQL_DSN environment variable
	ConnectByEnvironment
)

type Connector

type Connector struct {
	DB *sql.DB
	// contains filtered or unexported fields
}

Connector contains information on how to connect to MySQL

func NewConnector added in v0.6.0

func NewConnector(flags Config) *Connector

NewConnector returns a connected Connector given the provided flags

func (*Connector) Connect

func (c *Connector) Connect()

Connect makes a connection to the database using the previously defined settings

func (*Connector) ConnectByConfig added in v1.1.0

func (c *Connector) ConnectByConfig(config mysql_defaults_file.Config)

ConnectByConfig connects to MySQL using various configuration settings needed to create the DSN.

func (*Connector) ConnectByDefaultsFile

func (c *Connector) ConnectByDefaultsFile(defaultsFile string)

ConnectByDefaultsFile connects to the database with the given defaults-file, or ~/.my.cnf if not provided.

func (*Connector) ConnectByEnvironment added in v0.7.5

func (c *Connector) ConnectByEnvironment()

ConnectByEnvironment connects using environment variables

func (Connector) DefaultsFile

func (c Connector) DefaultsFile() string

DefaultsFile returns the defaults file

func (*Connector) SetConnectBy

func (c *Connector) SetConnectBy(method ConnectMethod)

SetConnectBy records how we want to connect

Jump to

Keyboard shortcuts

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