go-zero/tools/goctl/model/sql/template/model.go

56 lines
1.4 KiB
Go
Raw Normal View History

package template
2020-07-29 17:11:41 +08:00
import (
"fmt"
"github.com/zeromicro/go-zero/tools/goctl/util"
)
2022-04-01 22:19:52 +08:00
// ModelCustom defines a template for extension
const ModelCustom = `package {{.pkg}}
{{if .withCache}}
import (
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
{{else}}
2022-04-01 22:19:52 +08:00
import "github.com/zeromicro/go-zero/core/stores/sqlx"
{{end}}
2022-04-01 22:19:52 +08:00
var _ {{.upperStartCamelObject}}Model = (*custom{{.upperStartCamelObject}}Model)(nil)
type (
// {{.upperStartCamelObject}}Model is an interface to be customized, add more methods here,
// and implement the added methods in custom{{.upperStartCamelObject}}Model.
{{.upperStartCamelObject}}Model interface {
{{.lowerStartCamelObject}}Model
}
custom{{.upperStartCamelObject}}Model struct {
*default{{.upperStartCamelObject}}Model
}
)
// New{{.upperStartCamelObject}}Model returns a model for the database table.
func New{{.upperStartCamelObject}}Model(conn sqlx.SqlConn{{if .withCache}}, c cache.CacheConf{{end}}) {{.upperStartCamelObject}}Model {
return &custom{{.upperStartCamelObject}}Model{
default{{.upperStartCamelObject}}Model: new{{.upperStartCamelObject}}Model(conn{{if .withCache}}, c{{end}}),
}
}
`
// ModelGen defines a template for model
var ModelGen = fmt.Sprintf(`%s
package {{.pkg}}
2020-07-29 17:11:41 +08:00
{{.imports}}
{{.vars}}
{{.types}}
{{.new}}
{{.delete}}
2020-07-29 17:11:41 +08:00
{{.find}}
{{.insert}}
2020-07-29 17:11:41 +08:00
{{.update}}
{{.extraMethod}}
2022-04-01 22:19:52 +08:00
{{.tableName}}
`, util.DoNotEditHead)