database

package
v0.0.0-...-dcafc8e Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// PostgresOpt is default connection option for postgres.
	PostgresOpt = ConnectOption{
		Dialect:  "postgres",
		Host:     "localhost",
		DBName:   "postgres",
		Port:     5432,
		User:     "postgres",
		Password: "postgres",
	}

	// SQLiteOpt is shared in-memory database.
	SQLiteOpt = ConnectOption{
		Dialect: "sqlite3",
		Host:    "file::memory:?cache=shared",
	}
)

Functions

func AutoMigrate

func AutoMigrate(models []any)

AutoMigrate migrates table.

func Finalize

func Finalize() error

Finalize finalizes singleton.

func GetDB

func GetDB() *gorm.DB

GetDB gets db from singleton.

func Initialize

func Initialize(opt ConnectOption) error

Initialize inits singleton.

func TestingInitialize

func TestingInitialize(opt ConnectOption) (funcFinalize func())

TestingInitialize creates new db for testing.

Types

type ConnectOption

type ConnectOption struct {
	Dialect  string
	Host     string
	Port     int // optional, if you append port in host, this option is unnecessary.
	DBName   string
	User     string
	Password string
	Config   gorm.Config
	Silence  bool

	Testing bool

	Logger logger.Interface
}

ConnectOption defines a generic connect option for all dialects.

func (*ConnectOption) CliFlags

func (opt *ConnectOption) CliFlags() []cli.Flag

CliFlags returns cli flag list.

func (*ConnectOption) ConnStr

func (opt *ConnectOption) ConnStr() string

ConnStr generates connection string.

func (*ConnectOption) Dialector

func (opt *ConnectOption) Dialector() gorm.Dialector

Dialector generates gorm Dialector.

Jump to

Keyboard shortcuts

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