You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
1.0 KiB
Smarty
30 lines
1.0 KiB
Smarty
3 years ago
|
|
||
|
func (m *default{{.upperStartCamelObject}}Model) FindOneBy{{.upperField}}(ctx context.Context, {{.in}}) (*{{.upperStartCamelObject}}, error) {
|
||
|
{{if .withCache}}{{.cacheKey}}
|
||
|
var resp {{.upperStartCamelObject}}
|
||
|
err := m.QueryRowIndexCtx(ctx, &resp, {{.cacheKeyVariable}}, m.formatPrimary, func(conn *gorm.DB, v interface{}) (interface{}, error) {
|
||
|
if err := conn.Model(&{{.upperStartCamelObject}}{}).Where("{{.originalField}}", {{.lowerStartCamelField}}).Take(&resp).Error; err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return resp.{{.upperStartCamelPrimaryKey}}, nil
|
||
|
}, m.queryPrimary)
|
||
|
switch err {
|
||
|
case nil:
|
||
|
return &resp, nil
|
||
|
case gormc.ErrNotFound:
|
||
|
return nil, ErrNotFound
|
||
|
default:
|
||
|
return nil, err
|
||
|
}
|
||
|
}{{else}}var resp {{.upperStartCamelObject}}
|
||
|
err := m.conn.WithContext(ctx).Model(&{{.upperStartCamelObject}}{}).Where("{{.originalField}}", {{.lowerStartCamelField}}).Take(&resp).Error
|
||
|
switch err {
|
||
|
case nil:
|
||
|
return &resp, nil
|
||
|
case gormc.ErrNotFound:
|
||
|
return nil, ErrNotFound
|
||
|
default:
|
||
|
return nil, err
|
||
|
}
|
||
|
}{{end}}
|