Skip to content

Commit

Permalink
add index creation in odm template
Browse files Browse the repository at this point in the history
  • Loading branch information
czyt committed Jul 17, 2023
1 parent 81b43a1 commit 8a1fd04
Show file tree
Hide file tree
Showing 3 changed files with 11 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.15",
Version: "0.1.16",
EnableBashCompletion: true,
Commands: []*cli.Command{
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ type {{.ModelName}}Provider interface {
Aggregate{{.ModelName}}(ctx context.Context, pipeline interface{}, opts ...*options.AggregateOptions) (*mongo.Cursor, error)
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)
CreateOne{{.ModelName}}Index(ctx context.Context, index mongo.IndexModel, opts ...*options.CreateIndexesOptions) (result string, err error)
CreateMany{{.ModelName}}(ctx context.Context, data []interface{}, opts ...*options.InsertManyOptions) (result *mongo.InsertManyResult, err error)
CreateMany{{.ModelName}}Index(ctx context.Context, index []mongo.IndexModel, opts ...*options.CreateIndexesOptions) (result []string, err error)
FindOne{{.ModelName}}(ctx context.Context, filter interface{}, opts ...*options.FindOneOptions) (result *{{.ModelName}}, err error)
FindOne{{.ModelName}}ById(ctx context.Context, id string, opts ...*options.FindOneOptions) (result *{{.ModelName}}, err error)
Find{{.ModelName}}(ctx context.Context, filter interface{}, opts ...*options.FindOptions) (result []*{{.ModelName}}, err error)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,18 @@ func ({{.ModelIdentifier}} {{.ModelNameLowCase}}DataRepo) CreateOne{{.ModelName}
return mgm.Coll({{.ModelIdentifier}}.model).InsertOne(ctx, data, opts...)
}

func ({{.ModelIdentifier}} {{.ModelNameLowCase}}DataRepo) CreateOne{{.ModelName}}Index(ctx context.Context, index mongo.IndexModel, opts ...*options.CreateIndexesOptions) (result string, err error) {
return mgm.Coll({{.ModelIdentifier}}.model).Indexes().CreateOne(ctx, index, opts...)
}

func ({{.ModelIdentifier}} {{.ModelNameLowCase}}DataRepo) CreateMany{{.ModelName}}(ctx context.Context, data []interface{}, opts ...*options.InsertManyOptions) (result *mongo.InsertManyResult, err error) {
return mgm.Coll({{.ModelIdentifier}}.model).InsertMany(ctx, data, opts...)
}

func ({{.ModelIdentifier}} {{.ModelNameLowCase}}DataRepo) Create{{.ModelName}}SessionIndex(ctx context.Context, indexes []mongo.IndexModel, opts ...*options.CreateIndexesOptions) (result []string, err error) {
return mgm.Coll({{.ModelIdentifier}}.model).Indexes().CreateMany(ctx, indexes, opts...)
}

func ({{.ModelIdentifier}} {{.ModelNameLowCase}}DataRepo) FindOne{{.ModelName}}(ctx context.Context, filter interface{}, opts ...*options.FindOneOptions) (result *{{.BizPkg}}.{{.ModelName}}, err error) {
result = &{{.BizPkg}}.{{.ModelName}}{}
if err = mgm.Coll({{.ModelIdentifier}}.model).FindOne(ctx, filter, opts...).Decode(result); err != nil {
Expand Down

0 comments on commit 8a1fd04

Please sign in to comment.