database

package
v0.0.0-...-e0c2b66 Latest Latest
Warning

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

Go to latest
Published: May 2, 2025 License: Apache-2.0 Imports: 41 Imported by: 0

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

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

func DataTooLong

func DataTooLong(err error) bool

func DeadlockFound

func DeadlockFound(err error) bool

func GetDriver deprecated

func GetDriver(logger log.Logger, config DatabaseConfig) (source.Driver, database.Driver, error)

Deprecated: Here to not break compatibility since it was once public.

func LoadTLSClientCertFromFile

func LoadTLSClientCertFromFile(logger log.Logger, certFile, keyFile string) (tls.Certificate, error)

func LoadTLSClientCertsFromConfig

func LoadTLSClientCertsFromConfig(logger log.Logger, config *MySQLConfig) ([]tls.Certificate, error)

func MySQLDataTooLong

func MySQLDataTooLong(err error) bool

MySQLDataTooLong returns true when the provided error matches the MySQL code for data too long for column (when trying to insert a value that is greater than the defined max size of the column).

func MySQLDeadlockFound

func MySQLDeadlockFound(err error) bool

MySQLDeadlockFound returns true when the provided error matches the MySQL code for deadlock found.

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, opts ...MigrateOption) (*sql.DB, error)

func NewPkgerSource

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

func NopInTx

func NopInTx() error

func PostgresDeadlockFound

func PostgresDeadlockFound(err error) bool

PostgresDeadlockFound returns true when the provided error matches the Postgres code for deadlock found.

func PostgresDriver

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

func PostgresUniqueViolation

func PostgresUniqueViolation(err error) bool

PostgresUniqueViolation returns true when the provided error matches the Postgres code for unique violation.

func RecordMySQLStats

func RecordMySQLStats(db *sql.DB) error

func RunMigrations

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

func RunMigrationsContext

func RunMigrationsContext(ctx context.Context, logger log.Logger, config DatabaseConfig, opts ...MigrateOption) error

func SpannerDriver

func SpannerDriver(config DatabaseConfig) (database.Driver, error)

func SpannerMigrationDriver

func SpannerMigrationDriver(cfg SpannerConfig, databaseName string) (database.Driver, error)

func SpannerUniqueViolation

func SpannerUniqueViolation(err error) bool

SpannerUniqueViolation returns true when the provided error matches the Spanner code for duplicate entries (violating a unique table constraint). Refer to https://cloud.google.com/spanner/docs/error-codes for Spanner error definitions, and https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto for error codes

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

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

type DatabaseConfig

type DatabaseConfig struct {
	MySQL        *MySQLConfig
	Spanner      *SpannerConfig
	Postgres     *PostgresConfig
	DatabaseName string
}

type ErrOpenConnections

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

func (e ErrOpenConnections) Error() string

type MigrateOption

type MigrateOption func(o *migrateOptions) error

func WithEmbeddedMigrations

func WithEmbeddedMigrations(f fs.FS) MigrateOption

func WithTimeout

func WithTimeout(dur time.Duration) MigrateOption

type MySQLConfig

type MySQLConfig struct {
	Address        string
	User           string
	Password       string
	Connections    ConnectionsConfig
	UseTLS         bool
	TLSCAFile      string
	VerifyCAFile   bool
	TLSClientCerts []TLSClientCertConfig

	// 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

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

type PostgresAlloyConfig

type PostgresAlloyConfig struct {
	InstanceURI string
	UseIAM      bool
	UsePSC      bool
}

type PostgresConfig

type PostgresConfig struct {
	Address     string
	User        string
	Password    string
	Connections ConnectionsConfig
	TLS         *PostgresTLSConfig
	Alloy       *PostgresAlloyConfig
}

type PostgresTLSConfig

type PostgresTLSConfig struct {
	CACertFile     string
	ClientKeyFile  string
	ClientCertFile string
}

type RunInTx

type RunInTx func() error

type SourceDriver

type SourceDriver struct {
	source.Driver
	// contains filtered or unexported fields
}

type SpannerConfig

type SpannerConfig struct {
	Project  string
	Instance string

	DisableCleanStatements bool
}

type TLSClientCertConfig

type TLSClientCertConfig struct {
	CertFilePath string
	KeyFilePath  string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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