Skip to content

Commit 20489c0

Browse files
Merge pull request #48 from chenmingyong0423/builder/aggregation
builder/aggregation: alphabetize and optimize constants and function names, add missing arithmetic operators
2 parents 847d83c + 322bcbe commit 20489c0

File tree

4 files changed

+347
-220
lines changed

4 files changed

+347
-220
lines changed

builder/aggregation/aggregation_stage_builder.go

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,84 +28,84 @@ func NewStageBuilder() *StageBuilder {
2828
}
2929

3030
func (b *StageBuilder) AddFields(value any) *StageBuilder {
31-
b.pipeline = append(b.pipeline, bson.D{bson.E{Key: AddFieldsOp, Value: value}})
31+
b.pipeline = append(b.pipeline, bson.D{bson.E{Key: StageAddFieldsOp, Value: value}})
3232
return b
3333
}
3434

3535
func (b *StageBuilder) Set(value any) *StageBuilder {
36-
b.pipeline = append(b.pipeline, bson.D{bson.E{Key: SetOp, Value: value}})
36+
b.pipeline = append(b.pipeline, bson.D{bson.E{Key: StageSetOp, Value: value}})
3737
return b
3838
}
3939

4040
func (b *StageBuilder) Bucket(groupBy any, boundaries []any, opt *BucketOptions) *StageBuilder {
4141
d := bson.D{
42-
bson.E{Key: GroupByOp, Value: groupBy},
43-
bson.E{Key: BoundariesOp, Value: boundaries},
42+
bson.E{Key: StageGroupByOp, Value: groupBy},
43+
bson.E{Key: StageBoundariesOp, Value: boundaries},
4444
}
4545
if opt != nil {
4646
if opt.DefaultKey != nil {
47-
d = append(d, bson.E{Key: DefaultOp, Value: opt.DefaultKey})
47+
d = append(d, bson.E{Key: StageDefaultOp, Value: opt.DefaultKey})
4848
}
4949
if opt.Output != nil {
50-
d = append(d, bson.E{Key: OutputOp, Value: opt.Output})
50+
d = append(d, bson.E{Key: StageOutputOp, Value: opt.Output})
5151
}
5252
}
53-
b.pipeline = append(b.pipeline, bson.D{bson.E{Key: BucketOp, Value: d}})
53+
b.pipeline = append(b.pipeline, bson.D{bson.E{Key: StageBucketOp, Value: d}})
5454
return b
5555
}
5656

5757
func (b *StageBuilder) BucketAuto(groupBy any, buckets int, opt *BucketAutoOptions) *StageBuilder {
5858
d := bson.D{
59-
bson.E{Key: GroupByOp, Value: groupBy},
60-
bson.E{Key: BucketsOp, Value: buckets},
59+
bson.E{Key: StageGroupByOp, Value: groupBy},
60+
bson.E{Key: StageBucketsOp, Value: buckets},
6161
}
6262
if opt != nil {
6363
if opt.Output != nil {
64-
d = append(d, bson.E{Key: OutputOp, Value: opt.Output})
64+
d = append(d, bson.E{Key: StageOutputOp, Value: opt.Output})
6565
}
6666
if opt.Granularity != "" {
67-
d = append(d, bson.E{Key: GranularityOp, Value: opt.Granularity})
67+
d = append(d, bson.E{Key: StageGranularityOp, Value: opt.Granularity})
6868
}
6969
}
70-
b.pipeline = append(b.pipeline, bson.D{bson.E{Key: BucketAutoOp, Value: d}})
70+
b.pipeline = append(b.pipeline, bson.D{bson.E{Key: StageBucketAutoOp, Value: d}})
7171
return b
7272
}
7373

7474
func (b *StageBuilder) Match(expression any) *StageBuilder {
75-
b.pipeline = append(b.pipeline, bson.D{bson.E{Key: MatchOp, Value: expression}})
75+
b.pipeline = append(b.pipeline, bson.D{bson.E{Key: StageMatchOp, Value: expression}})
7676
return b
7777
}
7878

7979
func (b *StageBuilder) Group(id any, accumulators ...bson.E) *StageBuilder {
8080
d := bson.D{{Key: "_id", Value: id}}
8181
d = append(d, accumulators...)
82-
b.pipeline = append(b.pipeline, bson.D{bson.E{Key: GroupOp, Value: d}})
82+
b.pipeline = append(b.pipeline, bson.D{bson.E{Key: StageGroupOp, Value: d}})
8383
return b
8484
}
8585

8686
func (b *StageBuilder) Sort(value any) *StageBuilder {
87-
b.pipeline = append(b.pipeline, bson.D{bson.E{Key: SortOp, Value: value}})
87+
b.pipeline = append(b.pipeline, bson.D{bson.E{Key: StageSortOp, Value: value}})
8888
return b
8989
}
9090

9191
func (b *StageBuilder) Project(value any) *StageBuilder {
92-
b.pipeline = append(b.pipeline, bson.D{bson.E{Key: ProjectOp, Value: value}})
92+
b.pipeline = append(b.pipeline, bson.D{bson.E{Key: StageProjectOp, Value: value}})
9393
return b
9494
}
9595

9696
func (b *StageBuilder) Limit(limit int64) *StageBuilder {
97-
b.pipeline = append(b.pipeline, bson.D{bson.E{Key: LimitOp, Value: limit}})
97+
b.pipeline = append(b.pipeline, bson.D{bson.E{Key: StageLimitOp, Value: limit}})
9898
return b
9999
}
100100

101101
func (b *StageBuilder) Skip(skip int64) *StageBuilder {
102-
b.pipeline = append(b.pipeline, bson.D{bson.E{Key: SkipOp, Value: skip}})
102+
b.pipeline = append(b.pipeline, bson.D{bson.E{Key: StageSkipOp, Value: skip}})
103103
return b
104104
}
105105

106106
func (b *StageBuilder) Unwind(path string, opt *UnWindOptions) *StageBuilder {
107107
if opt == nil {
108-
b.pipeline = append(b.pipeline, bson.D{{Key: UnwindOp, Value: path}})
108+
b.pipeline = append(b.pipeline, bson.D{{Key: StageUnwindOp, Value: path}})
109109
} else {
110110
d := bson.D{{Key: "path", Value: path}}
111111
if opt.IncludeArrayIndex != "" {
@@ -114,28 +114,28 @@ func (b *StageBuilder) Unwind(path string, opt *UnWindOptions) *StageBuilder {
114114
if opt.PreserveNullAndEmptyArrays {
115115
d = append(d, bson.E{Key: "preserveNullAndEmptyArrays", Value: opt.PreserveNullAndEmptyArrays})
116116
}
117-
b.pipeline = append(b.pipeline, bson.D{{Key: UnwindOp, Value: d}})
117+
b.pipeline = append(b.pipeline, bson.D{{Key: StageUnwindOp, Value: d}})
118118
}
119119
return b
120120
}
121121

122122
func (b *StageBuilder) ReplaceWith(replacementDocument any) *StageBuilder {
123-
b.pipeline = append(b.pipeline, bson.D{{Key: ReplaceWithOp, Value: replacementDocument}})
123+
b.pipeline = append(b.pipeline, bson.D{{Key: StageReplaceWithOp, Value: replacementDocument}})
124124
return b
125125
}
126126

127127
func (b *StageBuilder) Facet(value any) *StageBuilder {
128-
b.pipeline = append(b.pipeline, bson.D{bson.E{Key: FacetOp, Value: value}})
128+
b.pipeline = append(b.pipeline, bson.D{bson.E{Key: StageFacetOp, Value: value}})
129129
return b
130130
}
131131

132132
func (b *StageBuilder) SortByCount(expression any) *StageBuilder {
133-
b.pipeline = append(b.pipeline, bson.D{bson.E{Key: SortByCountOp, Value: expression}})
133+
b.pipeline = append(b.pipeline, bson.D{bson.E{Key: StageSortByCountOp, Value: expression}})
134134
return b
135135
}
136136

137137
func (b *StageBuilder) Count(countName string) *StageBuilder {
138-
b.pipeline = append(b.pipeline, bson.D{bson.E{Key: CountOp, Value: countName}})
138+
b.pipeline = append(b.pipeline, bson.D{bson.E{Key: StageCountOp, Value: countName}})
139139
return b
140140
}
141141

0 commit comments

Comments
 (0)