gorm

package
v8.12.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyDatabaseName is returned when a database configuration contains an empty database name
	ErrEmptyDatabaseName = errors.New("db config contains empty database name")
)

Functions

func CleanAndMigrateModels

func CleanAndMigrateModels(tx *gorm.DB, models ...interface{}) error

CleanAndMigrateModels drops existing target model tables and recreates them.

func DropModels

func DropModels(tx *gorm.DB, models ...interface{}) error

DropModels drops database models.

func GetDBFromEnvVars

func GetDBFromEnvVars() (*gorm.DB, error)

GetDBFromEnvVars reads environment variables to return a Gorm database connection.

func GetTestDBFromEnvVars

func GetTestDBFromEnvVars() (*gorm.DB, error)

GetTestDBFromEnvVars reads environment variables to return a Gorm database connection to a test database. The test database will have "_test" automatically appended to the target database name.

func MigrateModels

func MigrateModels(tx *gorm.DB, models ...interface{}) error

MigrateModels migrates database models. If the model table already exists, it will be updated to reflect the model structure. The table will only have columns added or updated but not dropped.

Types

type ArrayString added in v8.10.0

type ArrayString []string

ArrayString is a custom data type for SQL databases. It adds support for an array of strings to MySQL.

func (*ArrayString) Scan added in v8.10.0

func (arr *ArrayString) Scan(src any) error

Scan fills out the current ArrayString with the string provided as source. It returns an error if source if not a string.

See sql.Scanner for more details.

func (*ArrayString) Value added in v8.10.0

func (arr *ArrayString) Value() (driver.Value, error)

Value takes the current ArrayString and converts it to a valid SQL value.

See driver.Valuer for more details.

Jump to

Keyboard shortcuts

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