Skip to content

Commit

Permalink
feat:add CreateXX method
Browse files Browse the repository at this point in the history
  • Loading branch information
czyt committed Feb 22, 2023
1 parent a0a45c7 commit 419d6c9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cmd/kilot/kilot.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func main() {
},
},
Name: "kilot",
Version: "0.1.12b1",
Version: "0.1.13",
EnableBashCompletion: true,
Commands: []*cli.Command{
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

type {{.ModelName}}Provider interface {
Create{{.ModelName}}(ctx context.Context, data *{{.ModelName}}, opts ...*options.InsertOneOptions) error
CreateOne{{.ModelName}}(ctx context.Context, data *{{.ModelName}}, opts ...*options.InsertOneOptions) (result *mongo.InsertOneResult, err error)
CreateMany{{.ModelName}}(ctx context.Context, data []interface{}, opts ...*options.InsertManyOptions) (result *mongo.InsertManyResult, err error)
FindOne{{.ModelName}}(ctx context.Context, filter interface{}, opts ...*options.FindOneOptions) (result *{{.ModelName}}, err error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ type {{.ModelNameLowCase}}DataRepo struct {
log *log.Helper
}

func ({{.ModelIdentifier}} {{.ModelNameLowCase}}DataRepo) Create{{.ModelName}}(ctx context.Context, data *{{.BizPkg}}.{{.ModelName}}, opts ...*options.InsertOneOptions) error {
return mgm.Coll({{.ModelIdentifier}}.model).CreateWithCtx(ctx, data, opts...)
}

func ({{.ModelIdentifier}} {{.ModelNameLowCase}}DataRepo) CreateOne{{.ModelName}}(ctx context.Context, data *{{.BizPkg}}.{{.ModelName}}, opts ...*options.InsertOneOptions) (result *mongo.InsertOneResult, err error) {
if data.CreatedAt.IsZero() {
data.CreatedAt = time.Now()
Expand Down

0 comments on commit 419d6c9

Please sign in to comment.