xdb

package
v0.0.0-...-73d6a9a Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2018 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DBHealthCheck

func DBHealthCheck(cfg *Config, db DB, logger xlog.OptionalLogger) xhealth.CheckMapping

DBHealthCheck register a health check for the database. officially it supports only mysql, postgres and mysql. however it try to register the unknown anyways.

func Module

func Module() fx.Option

Module provides an *sql.DB properly configured with values from env vars it also register itself in the health check module.

Types

type Config

type Config struct {
	// DriverName can be one of sqlite, mysql or postgres
	DriverName string           `yaml:"driver"`
	DSN        string           `yaml:"dsn"`
	Connection ConfigConnection `yaml:"connection"`
}

Config holds options to configure the database sql.DB pool of connections

func LoadConfig

func LoadConfig(params LoadConfigParams) (*Config, error)

type ConfigConnection

type ConfigConnection struct {
	MaxIdle     int           `yaml:"max_idle"`
	MaxOpen     int           `yaml:"max_open"`
	MaxLifetime time.Duration `yaml:"max_lifetime"`
}

type DB

type DB struct {
	fx.In

	DB *sql.DB `name:"x_sql_db"`
}

type DBQualifier

type DBQualifier struct {
	fx.Out

	DB *sql.DB `name:"x_sql_db"`
}

func NewDB

func NewDB(cfg *Config) (DBQualifier, error)

NewDB creates a sql.SB with the given config.

type LoadConfigParams

type LoadConfigParams struct {
	fx.In

	Provider config.Provider `optional:"true"`
}

Jump to

Keyboard shortcuts

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