2016-09-21 06:07:50 +02:00
|
|
|
{{- if not .NoHooks -}}
|
2016-06-20 07:22:50 +02:00
|
|
|
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
|
|
|
|
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
|
2016-08-28 12:54:46 +02:00
|
|
|
var {{$varNameSingular}}BeforeInsertHooks []{{$tableNameSingular}}Hook
|
2016-04-13 15:51:58 +02:00
|
|
|
var {{$varNameSingular}}BeforeUpdateHooks []{{$tableNameSingular}}Hook
|
2016-08-28 13:13:45 +02:00
|
|
|
var {{$varNameSingular}}BeforeDeleteHooks []{{$tableNameSingular}}Hook
|
2016-08-04 16:20:17 +02:00
|
|
|
var {{$varNameSingular}}BeforeUpsertHooks []{{$tableNameSingular}}Hook
|
2016-08-28 13:13:45 +02:00
|
|
|
|
2016-08-28 12:54:46 +02:00
|
|
|
var {{$varNameSingular}}AfterInsertHooks []{{$tableNameSingular}}Hook
|
2016-08-28 13:13:45 +02:00
|
|
|
var {{$varNameSingular}}AfterSelectHooks []{{$tableNameSingular}}Hook
|
2016-04-13 15:51:58 +02:00
|
|
|
var {{$varNameSingular}}AfterUpdateHooks []{{$tableNameSingular}}Hook
|
2016-08-28 13:13:45 +02:00
|
|
|
var {{$varNameSingular}}AfterDeleteHooks []{{$tableNameSingular}}Hook
|
2016-08-04 16:20:17 +02:00
|
|
|
var {{$varNameSingular}}AfterUpsertHooks []{{$tableNameSingular}}Hook
|
2016-04-13 15:51:58 +02:00
|
|
|
|
2016-08-28 12:54:46 +02:00
|
|
|
// doBeforeInsertHooks executes all "before insert" hooks.
|
2016-08-29 14:38:19 +02:00
|
|
|
func (o *{{$tableNameSingular}}) doBeforeInsertHooks(exec boil.Executor) (err error) {
|
2016-09-14 10:08:30 +02:00
|
|
|
for _, hook := range {{$varNameSingular}}BeforeInsertHooks {
|
|
|
|
if err := hook(exec, o); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2016-04-13 15:51:58 +02:00
|
|
|
|
2016-09-14 10:08:30 +02:00
|
|
|
return nil
|
2016-04-13 15:51:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// doBeforeUpdateHooks executes all "before Update" hooks.
|
2016-08-29 14:38:19 +02:00
|
|
|
func (o *{{$tableNameSingular}}) doBeforeUpdateHooks(exec boil.Executor) (err error) {
|
2016-09-14 10:08:30 +02:00
|
|
|
for _, hook := range {{$varNameSingular}}BeforeUpdateHooks {
|
|
|
|
if err := hook(exec, o); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2016-04-13 15:51:58 +02:00
|
|
|
|
2016-09-14 10:08:30 +02:00
|
|
|
return nil
|
2016-04-13 15:51:58 +02:00
|
|
|
}
|
|
|
|
|
2016-08-28 13:13:45 +02:00
|
|
|
// doBeforeDeleteHooks executes all "before Delete" hooks.
|
2016-08-29 14:38:19 +02:00
|
|
|
func (o *{{$tableNameSingular}}) doBeforeDeleteHooks(exec boil.Executor) (err error) {
|
2016-09-14 10:08:30 +02:00
|
|
|
for _, hook := range {{$varNameSingular}}BeforeDeleteHooks {
|
|
|
|
if err := hook(exec, o); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2016-08-28 13:13:45 +02:00
|
|
|
|
2016-09-14 10:08:30 +02:00
|
|
|
return nil
|
2016-08-28 13:13:45 +02:00
|
|
|
}
|
|
|
|
|
2016-08-04 05:11:45 +02:00
|
|
|
// doBeforeUpsertHooks executes all "before Upsert" hooks.
|
2016-08-29 14:38:19 +02:00
|
|
|
func (o *{{$tableNameSingular}}) doBeforeUpsertHooks(exec boil.Executor) (err error) {
|
2016-09-14 10:08:30 +02:00
|
|
|
for _, hook := range {{$varNameSingular}}BeforeUpsertHooks {
|
|
|
|
if err := hook(exec, o); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2016-08-04 05:11:45 +02:00
|
|
|
|
2016-09-14 10:08:30 +02:00
|
|
|
return nil
|
2016-08-04 05:11:45 +02:00
|
|
|
}
|
|
|
|
|
2016-08-28 12:54:46 +02:00
|
|
|
// doAfterInsertHooks executes all "after Insert" hooks.
|
2016-08-29 14:38:19 +02:00
|
|
|
func (o *{{$tableNameSingular}}) doAfterInsertHooks(exec boil.Executor) (err error) {
|
2016-09-14 10:08:30 +02:00
|
|
|
for _, hook := range {{$varNameSingular}}AfterInsertHooks {
|
|
|
|
if err := hook(exec, o); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2016-04-13 15:51:58 +02:00
|
|
|
|
2016-09-14 10:08:30 +02:00
|
|
|
return nil
|
2016-04-13 15:51:58 +02:00
|
|
|
}
|
|
|
|
|
2016-08-28 13:13:45 +02:00
|
|
|
// doAfterSelectHooks executes all "after Select" hooks.
|
2016-08-29 14:38:19 +02:00
|
|
|
func (o *{{$tableNameSingular}}) doAfterSelectHooks(exec boil.Executor) (err error) {
|
2016-09-14 10:08:30 +02:00
|
|
|
for _, hook := range {{$varNameSingular}}AfterSelectHooks {
|
|
|
|
if err := hook(exec, o); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2016-08-28 13:13:45 +02:00
|
|
|
|
2016-09-14 10:08:30 +02:00
|
|
|
return nil
|
2016-08-28 13:13:45 +02:00
|
|
|
}
|
|
|
|
|
2016-04-13 15:51:58 +02:00
|
|
|
// doAfterUpdateHooks executes all "after Update" hooks.
|
2016-08-29 14:38:19 +02:00
|
|
|
func (o *{{$tableNameSingular}}) doAfterUpdateHooks(exec boil.Executor) (err error) {
|
2016-09-14 10:08:30 +02:00
|
|
|
for _, hook := range {{$varNameSingular}}AfterUpdateHooks {
|
|
|
|
if err := hook(exec, o); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2016-04-13 15:51:58 +02:00
|
|
|
|
2016-09-14 10:08:30 +02:00
|
|
|
return nil
|
2016-04-13 15:51:58 +02:00
|
|
|
}
|
|
|
|
|
2016-08-28 13:13:45 +02:00
|
|
|
// doAfterDeleteHooks executes all "after Delete" hooks.
|
2016-08-29 14:38:19 +02:00
|
|
|
func (o *{{$tableNameSingular}}) doAfterDeleteHooks(exec boil.Executor) (err error) {
|
2016-09-14 10:08:30 +02:00
|
|
|
for _, hook := range {{$varNameSingular}}AfterDeleteHooks {
|
|
|
|
if err := hook(exec, o); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2016-08-28 13:13:45 +02:00
|
|
|
|
2016-09-14 10:08:30 +02:00
|
|
|
return nil
|
2016-08-28 13:13:45 +02:00
|
|
|
}
|
|
|
|
|
2016-08-04 05:11:45 +02:00
|
|
|
// doAfterUpsertHooks executes all "after Upsert" hooks.
|
2016-08-29 14:38:19 +02:00
|
|
|
func (o *{{$tableNameSingular}}) doAfterUpsertHooks(exec boil.Executor) (err error) {
|
2016-09-14 10:08:30 +02:00
|
|
|
for _, hook := range {{$varNameSingular}}AfterUpsertHooks {
|
|
|
|
if err := hook(exec, o); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2016-08-04 05:11:45 +02:00
|
|
|
|
2016-09-14 10:08:30 +02:00
|
|
|
return nil
|
2016-08-04 05:11:45 +02:00
|
|
|
}
|
|
|
|
|
2016-09-15 06:20:35 +02:00
|
|
|
// Add{{$tableNameSingular}}Hook registers your hook function for all future operations.
|
2016-09-01 03:12:46 +02:00
|
|
|
func Add{{$tableNameSingular}}Hook(hookPoint boil.HookPoint, {{$varNameSingular}}Hook {{$tableNameSingular}}Hook) {
|
2016-09-14 10:08:30 +02:00
|
|
|
switch hookPoint {
|
|
|
|
case boil.BeforeInsertHook:
|
|
|
|
{{$varNameSingular}}BeforeInsertHooks = append({{$varNameSingular}}BeforeInsertHooks, {{$varNameSingular}}Hook)
|
|
|
|
case boil.BeforeUpdateHook:
|
|
|
|
{{$varNameSingular}}BeforeUpdateHooks = append({{$varNameSingular}}BeforeUpdateHooks, {{$varNameSingular}}Hook)
|
|
|
|
case boil.BeforeDeleteHook:
|
|
|
|
{{$varNameSingular}}BeforeDeleteHooks = append({{$varNameSingular}}BeforeDeleteHooks, {{$varNameSingular}}Hook)
|
|
|
|
case boil.BeforeUpsertHook:
|
|
|
|
{{$varNameSingular}}BeforeUpsertHooks = append({{$varNameSingular}}BeforeUpsertHooks, {{$varNameSingular}}Hook)
|
|
|
|
case boil.AfterInsertHook:
|
|
|
|
{{$varNameSingular}}AfterInsertHooks = append({{$varNameSingular}}AfterInsertHooks, {{$varNameSingular}}Hook)
|
|
|
|
case boil.AfterSelectHook:
|
|
|
|
{{$varNameSingular}}AfterSelectHooks = append({{$varNameSingular}}AfterSelectHooks, {{$varNameSingular}}Hook)
|
|
|
|
case boil.AfterUpdateHook:
|
|
|
|
{{$varNameSingular}}AfterUpdateHooks = append({{$varNameSingular}}AfterUpdateHooks, {{$varNameSingular}}Hook)
|
|
|
|
case boil.AfterDeleteHook:
|
|
|
|
{{$varNameSingular}}AfterDeleteHooks = append({{$varNameSingular}}AfterDeleteHooks, {{$varNameSingular}}Hook)
|
|
|
|
case boil.AfterUpsertHook:
|
|
|
|
{{$varNameSingular}}AfterUpsertHooks = append({{$varNameSingular}}AfterUpsertHooks, {{$varNameSingular}}Hook)
|
|
|
|
}
|
2016-04-13 15:51:58 +02:00
|
|
|
}
|
2016-08-28 12:48:50 +02:00
|
|
|
{{- end}}
|