db

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrDuplicateEntry indicates a 'unique' constraint violation on insert.
	// Message: Duplicate entry '%s' for key %d
	ErrDuplicateEntry = 1062
	// ErrNoResults indicates the MySQL query returned no rows.
	// Message: Query was empty
	ErrNoResults = 1065
)

The following covers a small set of the MySQL numerical error codes. See https://dev.mysql.com/doc/refman/8.0/en/server-error-reference.html for more information.

Variables

This section is empty.

Functions

func GetTxOrFailTesting

func GetTxOrFailTesting(t *testing.T, db *sqlx.DB) *sqlx.Tx

GetTxOrFailTesting creates and returns a database transaction, or will end the unit test by calling t.Fatal()

func MustConnect

func MustConnect(config Config) *sqlx.DB

MustConnect connects and returns a database connection, or calls os.Exit(1).

This sets several default parameters for the MySQL database:

  • collation: Sets the charset, but avoids the additional queries of charset
  • parseTime: changes the output type of DATE and DATETIME values to time.Time instead of []byte / string
  • interpolateParams: Reduces the number of round trips required to interpolate placeholders (i.e. ?)

func SetupBenchmarkDatabase added in v0.3.0

func SetupBenchmarkDatabase(b *testing.B, config Config, scriptPath string) *sqlx.DB

SetupBenchmarkDatabase creates and returns an empty database, using the the database name foo_test, where 'foo' is the name in the config.

func SetupTestingDatabase

func SetupTestingDatabase(t *testing.T, config Config, scriptPath string) *sqlx.DB

SetupTestingDatabase creates and returns an empty database, using the the database name foo_test, where 'foo' is the name in the config.

Types

type Config

type Config struct {
	// Username: MySQL user to login as.
	Username string
	// Password: The MySQL user's password.
	Password string
	// Address: Either 'localhost' or an IP such as '192.168.1.100'
	Address string
	// DBName: The name of the MySQL database to use.
	DBName string
}

Config holds the database configuration, required for connecting to and using the database.

Jump to

Keyboard shortcuts

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