database

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2021 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ProviderProductionSet provides a new Manager for use in production.
	ProviderProductionSet = wire.NewSet(Provide, ProvideGORM, Cfg)

	// ProviderTestSet provides a new MockManager for testing.
	ProviderTestSet = wire.NewSet(ProvideMock, CfgTest)
)

Functions

func ProvideGORM

func ProvideGORM(cfg *Config) (*gorm.DB, func(), error)

ProvideGORM provides a DB using the configuration properties provided by the given Config.

Types

type Config

type Config struct {
	URL             string
	MaxOpenConns    int
	MaxIdleConns    int
	ConnMaxLifetime time.Duration

	Logger *log.Log
	// contains filtered or unexported fields
}

Config contains the parameters for configuring a database.

func Cfg

func Cfg(v *viper.Viper, logger *log.Log) (*Config, error)

Cfg provides a new Config using values from a Viper.

func CfgTest

func CfgTest(cfg Config) (*Config, error)

CfgTest provides the passed Config.

type Manager

type Manager struct {
	DB *gorm.DB
	// contains filtered or unexported fields
}

Manager manages a connection to a database.

func Build

func Build(v *viper.Viper, log2 *log.Log) (*Manager, func(), error)

func New

func New(cfg Config, db *gorm.DB) *Manager

New returns a new instance of Manager configured with the given Config and DB.

func Provide

func Provide(cfg *Config, db *gorm.DB) (*Manager, error)

Provide provides a new Manager containing the given Config and DB.

type MockManager

type MockManager struct {
	Manager *Manager
	Mock    *sqlmock.Sqlmock
}

MockManager manages a mock connection to a database.

func BuildTest

func BuildTest(cfg Config) (*MockManager, func(), error)

func ProvideMock

func ProvideMock(cfg *Config) (*MockManager, func(), error)

ProvideMock provies a new MockManager containing the given Config.

Jump to

Keyboard shortcuts

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