feat: update gen_model to support provider
This commit is contained in:
53
pkg/ast/model/provider.gen.go.tpl
Normal file
53
pkg/ast/model/provider.gen.go.tpl
Normal file
@@ -0,0 +1,53 @@
|
||||
// Code generated by the atomctl ; DO NOT EDIT.
|
||||
// Code generated by the atomctl ; DO NOT EDIT.
|
||||
// Code generated by the atomctl ; DO NOT EDIT.
|
||||
package model
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
|
||||
"go.ipao.vip/atom"
|
||||
"go.ipao.vip/atom/container"
|
||||
"go.ipao.vip/atom/contracts"
|
||||
"go.ipao.vip/atom/opt"
|
||||
)
|
||||
|
||||
var db *sql.DB
|
||||
{{- range . }}
|
||||
var {{.PascalTable}}Model *{{.PascalTable}}
|
||||
{{- end }}
|
||||
|
||||
func Transaction(ctx context.Context) (*sql.Tx, error) {
|
||||
return db.Begin()
|
||||
}
|
||||
func DB() *sql.DB {
|
||||
return db
|
||||
}
|
||||
|
||||
func Provide(opts ...opt.Option) error {
|
||||
{{- range . }}
|
||||
if err := container.Container.Provide(func() (*{{.PascalTable}}, error) {
|
||||
obj := &{{.PascalTable}}{}
|
||||
return obj, nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
{{ end }}
|
||||
|
||||
if err := container.Container.Provide(func(
|
||||
_db *sql.DB,
|
||||
{{- range . }}
|
||||
{{.CamelTable}} *{{.PascalTable}},
|
||||
{{- end }}
|
||||
) (contracts.Initial, error) {
|
||||
db = _db
|
||||
{{- range . }}
|
||||
{{.PascalTable}}Model = {{.CamelTable}}
|
||||
{{- end }}
|
||||
|
||||
return nil, nil
|
||||
}, atom.GroupInitial); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user