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.
22 lines
1022 B
Smarty
22 lines
1022 B
Smarty
2 years ago
|
|
||
|
func (m *default{{.upperStartCamelObject}}Model) FindOneBy{{.upperField}}(ctx context.Context, tx *gorm.DB, {{.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 := gormx.WithTx(ctx, conn, tx).Model(&{{.upperStartCamelObject}}{}).Where("{{.originalField}}", {{.lowerStartCamelField}}).Take(&resp).Error; err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return resp.{{.upperStartCamelPrimaryKey}}, nil
|
||
|
}, m.queryPrimary)
|
||
|
if err = gormx.WrapSelectErr(err); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return &resp, nil
|
||
|
}{{else}}var resp {{.upperStartCamelObject}}
|
||
|
err := gormx.WithTx(ctx, m.DB, tx).Model(&{{.upperStartCamelObject}}{}).Where("{{.originalField}}", {{.lowerStartCamelField}}).Take(&resp).Error
|
||
|
if err = gormx.WrapSelectErr(err); err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
return &resp, nil
|
||
|
}{{end}}
|