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.

26 lines
849 B
Smarty

3 years ago
func (m *default{{.upperStartCamelObject}}Model) FindOne(ctx context.Context, {{.lowerStartCamelPrimaryKey}} {{.dataType}}) (*{{.upperStartCamelObject}}, error) {
{{if .withCache}}{{.cacheKey}}
var resp {{.upperStartCamelObject}}
3 years ago
err := m.QueryRowCtx(ctx, &resp, {{.cacheKeyVariable}}, func(conn *gorm.DB) *gorm.DB {
return conn.Where("id = ?", {{.lowerStartCamelPrimaryKey}})
3 years ago
})
switch err {
case nil:
return &resp, nil
3 years ago
case gormc.ErrNotFound:
3 years ago
return nil, ErrNotFound
default:
return nil, err
3 years ago
}{{else}}var resp {{.upperStartCamelObject}}
err := m.conn.WithContext(ctx).Model(&{{.upperStartCamelObject}}{}).Where("{{.originalPrimaryKey}} = ?", {{.lowerStartCamelPrimaryKey}}).Take(&resp).Error
3 years ago
switch err {
case nil:
return &resp, nil
3 years ago
case gormc.ErrNotFound:
3 years ago
return nil, ErrNotFound
default:
return nil, err
}{{end}}
}