Remove BeforeSelect hook (makes no sense)
This commit is contained in:
parent
2a5630ce3e
commit
e2553705e1
3 changed files with 5 additions and 34 deletions
|
@ -5,14 +5,13 @@ type HookPoint int
|
||||||
|
|
||||||
// the hook point constants
|
// the hook point constants
|
||||||
const (
|
const (
|
||||||
HookAfterInsert HookPoint = iota + 1
|
HookBeforeInsert HookPoint = iota + 1
|
||||||
|
HookBeforeUpdate
|
||||||
|
HookBeforeDelete
|
||||||
|
HookBeforeUpsert
|
||||||
|
HookAfterInsert
|
||||||
HookAfterSelect
|
HookAfterSelect
|
||||||
HookAfterUpdate
|
HookAfterUpdate
|
||||||
HookAfterDelete
|
HookAfterDelete
|
||||||
HookAfterUpsert
|
HookAfterUpsert
|
||||||
HookBeforeInsert
|
|
||||||
HookBeforeSelect
|
|
||||||
HookBeforeUpdate
|
|
||||||
HookBeforeDelete
|
|
||||||
HookBeforeUpsert
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
|
{{- $tableNameSingular := .Table.Name | singular | titleCase -}}
|
||||||
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
|
{{- $varNameSingular := .Table.Name | singular | camelCase -}}
|
||||||
var {{$varNameSingular}}BeforeInsertHooks []{{$tableNameSingular}}Hook
|
var {{$varNameSingular}}BeforeInsertHooks []{{$tableNameSingular}}Hook
|
||||||
var {{$varNameSingular}}BeforeSelectHooks []{{$tableNameSingular}}Hook
|
|
||||||
var {{$varNameSingular}}BeforeUpdateHooks []{{$tableNameSingular}}Hook
|
var {{$varNameSingular}}BeforeUpdateHooks []{{$tableNameSingular}}Hook
|
||||||
var {{$varNameSingular}}BeforeDeleteHooks []{{$tableNameSingular}}Hook
|
var {{$varNameSingular}}BeforeDeleteHooks []{{$tableNameSingular}}Hook
|
||||||
var {{$varNameSingular}}BeforeUpsertHooks []{{$tableNameSingular}}Hook
|
var {{$varNameSingular}}BeforeUpsertHooks []{{$tableNameSingular}}Hook
|
||||||
|
@ -24,17 +23,6 @@ func (o *{{$tableNameSingular}}) doBeforeInsertHooks() (err error) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// doBeforeSelectHooks executes all "before Select" hooks.
|
|
||||||
func (o *{{$tableNameSingular}}) doBeforeSelectHooks() (err error) {
|
|
||||||
for _, hook := range {{$varNameSingular}}BeforeSelectHooks {
|
|
||||||
if err := hook(o); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// doBeforeUpdateHooks executes all "before Update" hooks.
|
// doBeforeUpdateHooks executes all "before Update" hooks.
|
||||||
func (o *{{$tableNameSingular}}) doBeforeUpdateHooks() (err error) {
|
func (o *{{$tableNameSingular}}) doBeforeUpdateHooks() (err error) {
|
||||||
for _, hook := range {{$varNameSingular}}BeforeUpdateHooks {
|
for _, hook := range {{$varNameSingular}}BeforeUpdateHooks {
|
||||||
|
@ -127,8 +115,6 @@ func {{$tableNameSingular}}AddHook(hookPoint boil.HookPoint, {{$varNameSingular}
|
||||||
switch hookPoint {
|
switch hookPoint {
|
||||||
case boil.HookBeforeInsert:
|
case boil.HookBeforeInsert:
|
||||||
{{$varNameSingular}}BeforeInsertHooks = append({{$varNameSingular}}BeforeInsertHooks, {{$varNameSingular}}Hook)
|
{{$varNameSingular}}BeforeInsertHooks = append({{$varNameSingular}}BeforeInsertHooks, {{$varNameSingular}}Hook)
|
||||||
case boil.HookBeforeSelect:
|
|
||||||
{{$varNameSingular}}BeforeSelectHooks = append({{$varNameSingular}}BeforeSelectHooks, {{$varNameSingular}}Hook)
|
|
||||||
case boil.HookBeforeUpdate:
|
case boil.HookBeforeUpdate:
|
||||||
{{$varNameSingular}}BeforeUpdateHooks = append({{$varNameSingular}}BeforeUpdateHooks, {{$varNameSingular}}Hook)
|
{{$varNameSingular}}BeforeUpdateHooks = append({{$varNameSingular}}BeforeUpdateHooks, {{$varNameSingular}}Hook)
|
||||||
case boil.HookBeforeDelete:
|
case boil.HookBeforeDelete:
|
||||||
|
|
|
@ -13,11 +13,6 @@ func {{$varNameSingular}}AfterInsertHook(o *{{$tableNameSingular}}) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func {{$varNameSingular}}BeforeSelectHook(o *{{$tableNameSingular}}) error {
|
|
||||||
*o = {{$tableNameSingular}}{}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func {{$varNameSingular}}AfterSelectHook(o *{{$tableNameSingular}}) error {
|
func {{$varNameSingular}}AfterSelectHook(o *{{$tableNameSingular}}) error {
|
||||||
*o = {{$tableNameSingular}}{}
|
*o = {{$tableNameSingular}}{}
|
||||||
return nil
|
return nil
|
||||||
|
@ -84,15 +79,6 @@ func test{{$tableNamePlural}}Hooks(t *testing.T) {
|
||||||
}
|
}
|
||||||
{{$varNameSingular}}AfterInsertHooks = []{{$tableNameSingular}}Hook{}
|
{{$varNameSingular}}AfterInsertHooks = []{{$tableNameSingular}}Hook{}
|
||||||
|
|
||||||
{{$tableNameSingular}}AddHook(boil.HookBeforeSelect, {{$varNameSingular}}BeforeSelectHook)
|
|
||||||
if err = o.doBeforeSelectHooks(); err != nil {
|
|
||||||
t.Errorf("Unable to execute doBeforeSelectHooks: %s", err)
|
|
||||||
}
|
|
||||||
if !reflect.DeepEqual(o, empty) {
|
|
||||||
t.Errorf("Expected BeforeSelectHook function to empty object, but got: %#v", o)
|
|
||||||
}
|
|
||||||
{{$varNameSingular}}BeforeSelectHooks = []{{$tableNameSingular}}Hook{}
|
|
||||||
|
|
||||||
{{$tableNameSingular}}AddHook(boil.HookAfterSelect, {{$varNameSingular}}AfterSelectHook)
|
{{$tableNameSingular}}AddHook(boil.HookAfterSelect, {{$varNameSingular}}AfterSelectHook)
|
||||||
if err = o.doAfterSelectHooks(); err != nil {
|
if err = o.doAfterSelectHooks(); err != nil {
|
||||||
t.Errorf("Unable to execute doAfterSelectHooks: %s", err)
|
t.Errorf("Unable to execute doAfterSelectHooks: %s", err)
|
||||||
|
|
Loading…
Reference in a new issue