2016-09-21 06:07:50 +02:00
|
|
|
{{- if not .NoHooks -}}
|
2016-07-06 08:02:35 +02:00
|
|
|
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
|
|
|
|
{{- $tableNamePlural := .Table.Name | plural | titleCase -}}
|
|
|
|
{{- $varNamePlural := .Table.Name | plural | camelCase -}}
|
|
|
|
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
|
2016-08-29 14:38:19 +02:00
|
|
|
func {{$varNameSingular}}BeforeInsertHook(e boil.Executor, o *{{$tableNameSingular}}) error {
|
2016-09-14 10:08:30 +02:00
|
|
|
*o = {{$tableNameSingular}}{}
|
|
|
|
return nil
|
2016-07-06 08:02:35 +02:00
|
|
|
}
|
|
|
|
|
2016-08-29 14:38:19 +02:00
|
|
|
func {{$varNameSingular}}AfterInsertHook(e boil.Executor, o *{{$tableNameSingular}}) error {
|
2016-09-14 10:08:30 +02:00
|
|
|
*o = {{$tableNameSingular}}{}
|
|
|
|
return nil
|
2016-07-06 08:02:35 +02:00
|
|
|
}
|
|
|
|
|
2016-08-29 14:38:19 +02:00
|
|
|
func {{$varNameSingular}}AfterSelectHook(e boil.Executor, o *{{$tableNameSingular}}) error {
|
2016-09-14 10:08:30 +02:00
|
|
|
*o = {{$tableNameSingular}}{}
|
|
|
|
return nil
|
2016-08-28 13:13:45 +02:00
|
|
|
}
|
|
|
|
|
2016-08-29 14:38:19 +02:00
|
|
|
func {{$varNameSingular}}BeforeUpdateHook(e boil.Executor, o *{{$tableNameSingular}}) error {
|
2016-09-14 10:08:30 +02:00
|
|
|
*o = {{$tableNameSingular}}{}
|
|
|
|
return nil
|
2016-07-06 08:02:35 +02:00
|
|
|
}
|
|
|
|
|
2016-08-29 14:38:19 +02:00
|
|
|
func {{$varNameSingular}}AfterUpdateHook(e boil.Executor, o *{{$tableNameSingular}}) error {
|
2016-09-14 10:08:30 +02:00
|
|
|
*o = {{$tableNameSingular}}{}
|
|
|
|
return nil
|
2016-07-06 08:02:35 +02:00
|
|
|
}
|
|
|
|
|
2016-08-29 14:38:19 +02:00
|
|
|
func {{$varNameSingular}}BeforeDeleteHook(e boil.Executor, o *{{$tableNameSingular}}) error {
|
2016-09-14 10:08:30 +02:00
|
|
|
*o = {{$tableNameSingular}}{}
|
|
|
|
return nil
|
2016-08-28 13:13:45 +02:00
|
|
|
}
|
|
|
|
|
2016-08-29 14:38:19 +02:00
|
|
|
func {{$varNameSingular}}AfterDeleteHook(e boil.Executor, o *{{$tableNameSingular}}) error {
|
2016-09-14 10:08:30 +02:00
|
|
|
*o = {{$tableNameSingular}}{}
|
|
|
|
return nil
|
2016-08-28 13:13:45 +02:00
|
|
|
}
|
|
|
|
|
2016-08-29 14:38:19 +02:00
|
|
|
func {{$varNameSingular}}BeforeUpsertHook(e boil.Executor, o *{{$tableNameSingular}}) error {
|
2016-09-14 10:08:30 +02:00
|
|
|
*o = {{$tableNameSingular}}{}
|
|
|
|
return nil
|
2016-08-28 13:13:45 +02:00
|
|
|
}
|
|
|
|
|
2016-08-29 14:38:19 +02:00
|
|
|
func {{$varNameSingular}}AfterUpsertHook(e boil.Executor, o *{{$tableNameSingular}}) error {
|
2016-09-14 10:08:30 +02:00
|
|
|
*o = {{$tableNameSingular}}{}
|
|
|
|
return nil
|
2016-08-28 13:13:45 +02:00
|
|
|
}
|
|
|
|
|
2016-08-15 11:36:38 +02:00
|
|
|
func test{{$tableNamePlural}}Hooks(t *testing.T) {
|
2016-09-14 10:08:30 +02:00
|
|
|
t.Parallel()
|
|
|
|
|
|
|
|
var err error
|
|
|
|
|
|
|
|
empty := &{{$tableNameSingular}}{}
|
|
|
|
o := &{{$tableNameSingular}}{}
|
|
|
|
|
|
|
|
seed := randomize.NewSeed()
|
|
|
|
if err = randomize.Struct(seed, o, {{$varNameSingular}}DBTypes, false); err != nil {
|
|
|
|
t.Errorf("Unable to randomize {{$tableNameSingular}} object: %s", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
Add{{$tableNameSingular}}Hook(boil.BeforeInsertHook, {{$varNameSingular}}BeforeInsertHook)
|
|
|
|
if err = o.doBeforeInsertHooks(nil); err != nil {
|
|
|
|
t.Errorf("Unable to execute doBeforeInsertHooks: %s", err)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(o, empty) {
|
|
|
|
t.Errorf("Expected BeforeInsertHook function to empty object, but got: %#v", o)
|
|
|
|
}
|
|
|
|
{{$varNameSingular}}BeforeInsertHooks = []{{$tableNameSingular}}Hook{}
|
|
|
|
|
|
|
|
Add{{$tableNameSingular}}Hook(boil.AfterInsertHook, {{$varNameSingular}}AfterInsertHook)
|
|
|
|
if err = o.doAfterInsertHooks(nil); err != nil {
|
|
|
|
t.Errorf("Unable to execute doAfterInsertHooks: %s", err)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(o, empty) {
|
|
|
|
t.Errorf("Expected AfterInsertHook function to empty object, but got: %#v", o)
|
|
|
|
}
|
|
|
|
{{$varNameSingular}}AfterInsertHooks = []{{$tableNameSingular}}Hook{}
|
|
|
|
|
|
|
|
Add{{$tableNameSingular}}Hook(boil.AfterSelectHook, {{$varNameSingular}}AfterSelectHook)
|
|
|
|
if err = o.doAfterSelectHooks(nil); err != nil {
|
|
|
|
t.Errorf("Unable to execute doAfterSelectHooks: %s", err)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(o, empty) {
|
|
|
|
t.Errorf("Expected AfterSelectHook function to empty object, but got: %#v", o)
|
|
|
|
}
|
|
|
|
{{$varNameSingular}}AfterSelectHooks = []{{$tableNameSingular}}Hook{}
|
|
|
|
|
|
|
|
Add{{$tableNameSingular}}Hook(boil.BeforeUpdateHook, {{$varNameSingular}}BeforeUpdateHook)
|
|
|
|
if err = o.doBeforeUpdateHooks(nil); err != nil {
|
|
|
|
t.Errorf("Unable to execute doBeforeUpdateHooks: %s", err)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(o, empty) {
|
|
|
|
t.Errorf("Expected BeforeUpdateHook function to empty object, but got: %#v", o)
|
|
|
|
}
|
|
|
|
{{$varNameSingular}}BeforeUpdateHooks = []{{$tableNameSingular}}Hook{}
|
|
|
|
|
|
|
|
Add{{$tableNameSingular}}Hook(boil.AfterUpdateHook, {{$varNameSingular}}AfterUpdateHook)
|
|
|
|
if err = o.doAfterUpdateHooks(nil); err != nil {
|
|
|
|
t.Errorf("Unable to execute doAfterUpdateHooks: %s", err)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(o, empty) {
|
|
|
|
t.Errorf("Expected AfterUpdateHook function to empty object, but got: %#v", o)
|
|
|
|
}
|
|
|
|
{{$varNameSingular}}AfterUpdateHooks = []{{$tableNameSingular}}Hook{}
|
|
|
|
|
|
|
|
Add{{$tableNameSingular}}Hook(boil.BeforeDeleteHook, {{$varNameSingular}}BeforeDeleteHook)
|
|
|
|
if err = o.doBeforeDeleteHooks(nil); err != nil {
|
|
|
|
t.Errorf("Unable to execute doBeforeDeleteHooks: %s", err)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(o, empty) {
|
|
|
|
t.Errorf("Expected BeforeDeleteHook function to empty object, but got: %#v", o)
|
|
|
|
}
|
|
|
|
{{$varNameSingular}}BeforeDeleteHooks = []{{$tableNameSingular}}Hook{}
|
|
|
|
|
|
|
|
Add{{$tableNameSingular}}Hook(boil.AfterDeleteHook, {{$varNameSingular}}AfterDeleteHook)
|
|
|
|
if err = o.doAfterDeleteHooks(nil); err != nil {
|
|
|
|
t.Errorf("Unable to execute doAfterDeleteHooks: %s", err)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(o, empty) {
|
|
|
|
t.Errorf("Expected AfterDeleteHook function to empty object, but got: %#v", o)
|
|
|
|
}
|
|
|
|
{{$varNameSingular}}AfterDeleteHooks = []{{$tableNameSingular}}Hook{}
|
|
|
|
|
|
|
|
Add{{$tableNameSingular}}Hook(boil.BeforeUpsertHook, {{$varNameSingular}}BeforeUpsertHook)
|
|
|
|
if err = o.doBeforeUpsertHooks(nil); err != nil {
|
|
|
|
t.Errorf("Unable to execute doBeforeUpsertHooks: %s", err)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(o, empty) {
|
|
|
|
t.Errorf("Expected BeforeUpsertHook function to empty object, but got: %#v", o)
|
|
|
|
}
|
|
|
|
{{$varNameSingular}}BeforeUpsertHooks = []{{$tableNameSingular}}Hook{}
|
|
|
|
|
|
|
|
Add{{$tableNameSingular}}Hook(boil.AfterUpsertHook, {{$varNameSingular}}AfterUpsertHook)
|
|
|
|
if err = o.doAfterUpsertHooks(nil); err != nil {
|
|
|
|
t.Errorf("Unable to execute doAfterUpsertHooks: %s", err)
|
|
|
|
}
|
|
|
|
if !reflect.DeepEqual(o, empty) {
|
|
|
|
t.Errorf("Expected AfterUpsertHook function to empty object, but got: %#v", o)
|
|
|
|
}
|
|
|
|
{{$varNameSingular}}AfterUpsertHooks = []{{$tableNameSingular}}Hook{}
|
2016-07-06 08:02:35 +02:00
|
|
|
}
|
2016-08-28 12:48:50 +02:00
|
|
|
{{- end}}
|