db

package
v0.0.107 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateCustomIndices

func CreateCustomIndices(tx *gorm.DB, model interface{}, tableName string) error

CreateCustomIndices creates custom indices if model implements models.CustomIndexer.

func CreateForeignKeyConstraintsSelf

func CreateForeignKeyConstraintsSelf(tx *gorm.DB, model interface{}, tableName string) error

CreateForeignKeyConstraintsSelf creates foreign key constraint if model implements models.ForeignKeyConstrainer.

func DeleteAllData

func DeleteAllData(appType types.AppType)

DeleteAllData with `DELETE` since TRUNCATE runs so slow in cockroachdb This method provides same functionality as `dropAllDatabase`

func Finalize

func Finalize()

Finalize closes the database and delete it from dbMap.

func GetDB

func GetDB(host ...Host) *gorm.DB

GetDB returns the database handle.

func Initialize

func Initialize(extraHosts ...Host)

Initialize initializes models. It only creates the connection instance, doesn't reset or migrate anything.

func NewDB

func NewDB(args string, _ Host) (db *gorm.DB, err error)

NewDB configures given params in shared flow and returns an ORM DB instance with same functionalities and features. In this package, we create global DB instance with shared params. For external package, e.g: record, it connects to restored instance with different params.

func Reset

func Reset(db *gorm.DB, appType types.AppType, force bool)

Reset resets the entire database. It will: 1. Drop all database. 2. Do migration (contains initial schema & default records).

func Transaction

func Transaction(db *gorm.DB, body func(*gorm.DB) error) (err error)

Transaction wraps the database transaction and to proper error handling.

Types

type DBApp

type DBApp interface {
	// Models returns the models for a given database app.
	Models() []interface{}

	// IsEmpty check if a given database is empty.
	IsEmpty(db *gorm.DB) bool

	// PreReset is executed before db is reset.
	PreReset(db *gorm.DB) error

	// PostReset is executed after db is reset.
	PostReset(db *gorm.DB) error
}

DBApp is an interface for different database applications.

type Host

type Host string

Host specifies the database host.

const (
	Default Host = "default"
	Master  Host = "master"
)

Host enums.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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