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.
ntool-biz/zero/template/1.4.3/model/find-one.tpl

18 lines
951 B
Smarty

func (m *default{{.upperStartCamelObject}}Model) FindOne(ctx context.Context, tx *gorm.DB, {{.lowerStartCamelPrimaryKey}} {{.dataType}}) (*{{.upperStartCamelObject}}, error) {
{{if .withCache}}{{.cacheKey}}
var resp {{.upperStartCamelObject}}
err := m.QueryCtx(ctx, &resp, {{.cacheKeyVariable}}, func(conn *gorm.DB, v interface{}) error {
return gormx.WithTx(ctx, conn, tx).Model(&{{.upperStartCamelObject}}{}).Where("{{.originalPrimaryKey}} = ?", {{.lowerStartCamelPrimaryKey}}).First(&resp).Error
})
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("{{.originalPrimaryKey}} = ?", {{.lowerStartCamelPrimaryKey}}).Take(&resp).Error
if err = gormx.WrapSelectErr(err); err != nil {
return nil, err
}
return &resp, nil{{end}}
}