db

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: Apache-2.0 Imports: 18 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConfigDefault = Config{
	Dialect:  DialectMySQL,
	Host:     "localhost",
	Port:     3306,
	User:     "root",
	Password: "",
	Database: "db",
	Timezone: "UTC",
	Debug:    false,

	ConnMaxIdleTime: 3 * time.Minute,
	ConnMaxLifetime: 30 * time.Minute,
	MaxOpenConns:    runtime.NumCPU() * 4,
	MaxIdleConns:    runtime.NumCPU() * 2,
}
View Source
var Module = fx.Module(
	"db",
	fx.Decorate(func(log *zap.Logger) *zap.Logger {
		return log.Named("db")
	}),
	fx.Provide(
		New,
		NewSQL,
	),
)

Functions

func AutoMigrate

func AutoMigrate(params CommandMigrateParams) error

func Migrate

func Migrate(params GooseMigrateParams) error

func New

func New(params Params) (*gorm.DB, error)

func NewSQL

func NewSQL(config Config) (*sql.DB, error)

func RegisterGoose

func RegisterGoose(storage GooseStorage)

func RegisterMigration

func RegisterMigration(migrator Migrator)

Types

type CommandMigrateParams

type CommandMigrateParams struct {
	fx.In

	Logger *zap.Logger
	DB     *gorm.DB
	Shut   fx.Shutdowner
}

type Config

type Config struct {
	Dialect  Dialect
	DSN      string
	Host     string
	Port     int
	User     string
	Password string
	Database string
	Timezone string
	Debug    bool

	ConnMaxIdleTime time.Duration
	ConnMaxLifetime time.Duration
	MaxOpenConns    int
	MaxIdleConns    int
}

type Dialect

type Dialect string
const (
	DialectMariaDB  Dialect = "mariadb"
	DialectMySQL    Dialect = "mysql"
	DialectPostgres Dialect = "postgres"
	DialectSQLite3  Dialect = "sqlite3"
)

type GooseMigrateParams

type GooseMigrateParams struct {
	fx.In

	Args cli.Args

	Config Config

	Logger *zap.Logger
	DB     *sql.DB
	Shut   fx.Shutdowner
}

type GooseStorage

type GooseStorage fs.FS

type Migrator

type Migrator func(*gorm.DB) error

type Params

type Params struct {
	fx.In

	Logger *zap.Logger
	Config Config
	SQL    *sql.DB
	LC     fx.Lifecycle
}

Jump to

Keyboard shortcuts

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