def

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2018 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AfterBuild

func AfterBuild(callback factory.Callback) definitionOption

AfterBuild sets callback called after the model struct been build. REMIND that AfterBuild callback will be called not only when Build a model struct but also when Create a model struct. Because to Create a model struct instance, we must build it first.

func AfterCreate

func AfterCreate(callback factory.Callback) definitionOption

AfterCreate sets callback called after the model struct been saved.

func Association

func Association(name, referenceField, associationReferenceField string, originalFactory *factory.Factory, opts ...definitionOption) definitionOption

Association defines the value of a association field

func BeforeCreate

func BeforeCreate(callback factory.Callback) definitionOption

BeforeCreate sets callback called before the model struct been saved.

func DynamicField

func DynamicField(name string, value factory.DynamicFieldValue) definitionOption

DynamicField defines the value generator of a dynamic field in the factory.

func Field

func Field(name string, value interface{}) definitionOption

Field defines the value of a field in the factory

func NewFactory

func NewFactory(model interface{}, table string, opts ...definitionOption) *factory.Factory

NewFactory defines a factory of a model struct. Parameter model is the model struct instance(or struct instance pointer). Parameter table represents which database table this model will be saved. Usage example: Defining factories

type Model struct {
		ID int64
		Name string
}

FactoryModel := NewFactory(Model{}, "model_table",

Field("Name", "test name"),
SequenceField("ID", func(n int64) interface{} {
	return n
}),
Trait("Chinese",
	Field("Country", "China"),
),
BeforeCreate(func(model interface{}) error {
	// do something
}),
AfterCreate(func(model interface{}) error {
	// do something
}),

)

func SequenceField

func SequenceField(name string, first int64, value factory.SequenceFieldValue) definitionOption

SequenceField defines the value of a squence field in the factory. Unique values in a specific format (for example, e-mail addresses) can be generated using sequences.

func Trait

func Trait(traitName string, opts ...definitionOption) definitionOption

Trait allows you to group fields together and then apply them to any factory.

Types

This section is empty.

Jump to

Keyboard shortcuts

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