database

package
v2.10.2 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearRegisteredModels added in v2.2.0

func ClearRegisteredModels()

ClearRegisteredModels unregister all models.

func Close

func Close()

Close the database connections if they exist.

func GetConnection

func GetConnection() *gorm.DB

GetConnection returns the global database connection pool. Creates a new connection pool if no connection is available.

The connections will be closed automatically on server shutdown so you don't need to call "Close()" when you're done with the database.

func GetRegisteredModels added in v2.2.0

func GetRegisteredModels() []interface{}

GetRegisteredModels get the registered models. The returned slice is a copy of the original, so it cannot be modified.

func Migrate

func Migrate()

Migrate migrates all registered models.

func RegisterModel

func RegisterModel(model interface{})

RegisterModel registers a model for auto-migration. When writing a model file, you should always register it in the init() function.

 func init() {
		database.RegisterModel(&MyModel{})
 }

Types

type Factory added in v2.2.0

type Factory struct {
	// contains filtered or unexported fields
}

Factory an object used to generate records or seed the database.

func NewFactory added in v2.2.0

func NewFactory(generator Generator) *Factory

NewFactory create a new Factory. The given generator function will be used to generate records.

func (*Factory) Generate added in v2.2.0

func (f *Factory) Generate(count uint) []interface{}

Generate a number of records using the given factory.

func (*Factory) Override added in v2.2.0

func (f *Factory) Override(override interface{}) *Factory

Override set an override model for generated records. Values present in the override model will replace the ones in the generated records. This function expects a struct pointer as parameter. Returns the same instance of `Factory` so this method can be chained.

func (*Factory) Save added in v2.2.0

func (f *Factory) Save(count uint) []interface{}

Save generate a number of records using the given factory and return the inserted records.

type Generator added in v2.2.0

type Generator func() interface{}

Generator a generator function generates a single record.

Jump to

Keyboard shortcuts

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