Skip to content

Commit

Permalink
feat:add replaceOne
Browse files Browse the repository at this point in the history
  • Loading branch information
czyt committed Oct 11, 2023
1 parent ce5d920 commit 37f9451
Show file tree
Hide file tree
Showing 3 changed files with 20 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.17",
Version: "0.1.18",
EnableBashCompletion: true,
Commands: []*cli.Command{
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func ({{.ModelIdentifier}} {{.ModelNameLowCase}}DataRepo) Find{{.ModelName}}(ctx
}
return result, nil
}
//TODO:implement ReplaceOne{{.ModelName}} and ReplaceOne{{.ModelName}}ById

func ({{.ModelIdentifier}} {{.ModelNameLowCase}}DataRepo) Estimated{{.ModelName}}Count(ctx context.Context, opts ...*options.EstimatedDocumentCountOptions) (int64, error) {
return {{.ModelIdentifier}}.coll.EstimatedDocumentCount(ctx, opts...)
Expand Down
18 changes: 18 additions & 0 deletions cmd/kilot/kratos/mongo/internal/templates/odm_data_layer_logic.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,24 @@ func ({{.ModelIdentifier}} {{.ModelNameLowCase}}DataRepo) Find{{.ModelName}}(ctx
return result, nil
}

func ({{.ModelIdentifier}} {{.ModelNameLowCase}}DataRepo) ReplaceOne{{.ModelName}}(ctx context.Context, filter interface{}, data *{{.BizPkg}}.{{.ModelName}}, opts ...*options.ReplaceOptions) (result *mongo.UpdateResult, err error) {
if data.CreatedAt.IsZero() {
data.CreatedAt = time.Now()
}
return mgm.Coll({{.ModelIdentifier}}.model).ReplaceOne(ctx, filter, data, opts...)
}

func ({{.ModelIdentifier}} {{.ModelNameLowCase}}DataRepo) ReplaceOne{{.ModelName}}ById(ctx context.Context, id string, data *{{.BizPkg}}.{{.ModelName}}, opts ...*options.ReplaceOptions) (result *mongo.UpdateResult, err error) {
recordId, err := t.model.PrepareID(id)
if err != nil {
return nil, err
}
if data.CreatedAt.IsZero() {
data.CreatedAt = time.Now()
}
return mgm.Coll({{.ModelIdentifier}}.model).ReplaceOne(ctx, bson.M{"_id": recordId}, data, opts...)
}

func ({{.ModelIdentifier}} {{.ModelNameLowCase}}DataRepo) Estimated{{.ModelName}}Count(ctx context.Context, opts ...*options.EstimatedDocumentCountOptions) (int64, error) {
return mgm.Coll({{.ModelIdentifier}}.model).EstimatedDocumentCount(ctx, opts...)
}
Expand Down

0 comments on commit 37f9451

Please sign in to comment.