db

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

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,
}
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
}

type Dialect

type Dialect string
const (
	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