database

package
v0.31.0 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2022 License: Apache-2.0 Imports: 32 Imported by: 4

Documentation

Overview

Copyright 2020 The Moov Authors Use of this source code is governed by an Apache License license that can be found in the LICENSE file.

Copyright 2020 The Moov Authors Use of this source code is governed by an Apache License license that can be found in the LICENSE file.

Copyright 2020 The Moov Authors Use of this source code is governed by an Apache License license that can be found in the LICENSE file.

Copyright 2020 The Moov Authors Use of this source code is governed by an Apache License license that can be found in the LICENSE file.

Copyright 2020 The Moov Authors Use of this source code is governed by an Apache License license that can be found in the LICENSE file.

Index

Constants

View Source
const MIGRATIONS_DIR = "/migrations/"

Variables

This section is empty.

Functions

func ApplyConnectionsConfig added in v0.17.0

func ApplyConnectionsConfig(db *sql.DB, connections *ConnectionsConfig, logger log.Logger) *sql.DB

func GetDriver

func GetDriver(db *sql.DB, config DatabaseConfig) (source.Driver, database.Driver, error)

func MySQLDriver

func MySQLDriver(db *sql.DB) (database.Driver, error)

func MySQLUniqueViolation

func MySQLUniqueViolation(err error) bool

MySQLUniqueViolation returns true when the provided error matches the MySQL code for duplicate entries (violating a unique table constraint).

func New

func New(ctx context.Context, logger log.Logger, config DatabaseConfig) (*sql.DB, error)

New establishes a database connection according to the type and environmental variables for that specific database.

func NewAndMigrate

func NewAndMigrate(ctx context.Context, logger log.Logger, config DatabaseConfig) (*sql.DB, error)

func NewPkgerSource added in v0.15.2

func NewPkgerSource(database string) (source.Driver, error)

func NopInTx added in v0.19.0

func NopInTx() error

func RecordMySQLStats added in v0.27.4

func RecordMySQLStats(db *sql.DB) error

func RunMigrations

func RunMigrations(logger log.Logger, config DatabaseConfig) error

func SQLite3Driver

func SQLite3Driver(db *sql.DB) (database.Driver, error)

func SQLiteUniqueViolation added in v0.14.0

func SQLiteUniqueViolation(err error) bool

SQLiteUniqueViolation returns true when the provided error matches the SQLite error for duplicate entries (violating a unique table constraint).

func UniqueViolation

func UniqueViolation(err error) bool

UniqueViolation returns true when the provided error matches a database error for duplicate entries (violating a unique table constraint).

Types

type ConnectionsConfig added in v0.17.0

type ConnectionsConfig struct {
	MaxOpen     int
	MaxIdle     int
	MaxLifetime time.Duration
	MaxIdleTime time.Duration
}

type DatabaseConfig

type DatabaseConfig struct {
	MySQL        *MySQLConfig
	SQLite       *SQLiteConfig
	DatabaseName string
}

type ErrOpenConnections added in v0.14.0

type ErrOpenConnections struct {
	Database       string
	NumConnections int
}

ErrOpenConnections describes the number of open connections that should have been closed by a call to Close(). All queries/transactions should call Close() to prevent unused, open connections.

func (ErrOpenConnections) Error added in v0.14.0

func (e ErrOpenConnections) Error() string

type MySQLConfig

type MySQLConfig struct {
	Address      string
	User         string
	Password     string
	Connections  ConnectionsConfig
	UseTLS       bool
	TLSCAFile    string
	VerifyCAFile bool

	// InsecureSkipVerify is a dangerous option which should be used with extreme caution.
	// This setting disables multiple security checks performed with TLS connections.
	InsecureSkipVerify bool
}

func (*MySQLConfig) MarshalJSON added in v0.20.0

func (m *MySQLConfig) MarshalJSON() ([]byte, error)

type RunInTx added in v0.19.0

type RunInTx func() error

type SQLiteConfig

type SQLiteConfig struct {
	Path string
}

type TestSQLiteDB

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

TestSQLiteDB is a wrapper around sql.DB for SQLite connections designed for tests to provide a clean database for each testcase. Callers should cleanup with Close() when finished.

func CreateTestSQLiteDB added in v0.14.0

func CreateTestSQLiteDB(t *testing.T) *TestSQLiteDB

CreateTestSQLiteDB returns a TestSQLiteDB which can be used in tests as a clean sqlite database. All migrations are ran on the db before.

Callers should call close on the returned *TestSQLiteDB.

func (*TestSQLiteDB) Close

func (r *TestSQLiteDB) Close() error

Jump to

Keyboard shortcuts

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