cleaner

package
Version: v42.0.0-...-56f38d9 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2017 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteCreatedEntities

func DeleteCreatedEntities(db *gorm.DB) func()

DeleteCreatedEntities records all created entities on the gorm.DB connection and returns a function which can be called on defer to delete created entities in reverse order on function exit.

In addition to that, the WIT cache is cleared as well in order to respect any deletions made to the db.

Usage:

func TestDatabaseActions(t *testing.T) {

	// setup database connection
	db := ....
	// setup auto clean up of created entities
	defer DeleteCreatedEntities(db)()

	repo := NewRepo(db)
	repo.Create(X)
	repo.Create(X)
	repo.Create(X)
}

Output:

2017/01/31 12:08:08 Deleting from x 6d143405-1232-40de-bc73-835b543cd972 2017/01/31 12:08:08 Deleting from x 0685068d-4934-4d9a-bac2-91eebbca9575 2017/01/31 12:08:08 Deleting from x 2d20944e-7952-40c1-bd15-f3fa1a70026d

Types

This section is empty.

Source Files

Jump to

Keyboard shortcuts

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