Documentation ¶
Index ¶
- func AfterBuild(callback factory.Callback) definitionOption
- func AfterCreate(callback factory.Callback) definitionOption
- func Association(name, referenceField, associationReferenceField string, ...) definitionOption
- func BeforeCreate(callback factory.Callback) definitionOption
- func DynamicField(name string, value factory.DynamicFieldValue) definitionOption
- func Field(name string, value interface{}) definitionOption
- func NewFactory(model interface{}, table string, opts ...definitionOption) *factory.Factory
- func SequenceField(name string, first int64, value factory.SequenceFieldValue) definitionOption
- func Trait(traitName string, opts ...definitionOption) definitionOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AfterBuild ¶
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 ¶
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 ¶
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 ¶
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.
Types ¶
This section is empty.