Skip to content

Commit 0813b46

Browse files
refactor(builder/query): alphabetize the constants, functions, and method names. (#49)
1 parent 20489c0 commit 0813b46

File tree

4 files changed

+127
-145
lines changed

4 files changed

+127
-145
lines changed

builder/query/array_query_builder.go

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -31,116 +31,116 @@ func (b *arrayQueryBuilder) All(key string, values ...any) *Builder {
3131
return b.parent
3232
}
3333

34-
// AllUint appends an element with '$all' key and given value to the builder's data slice.
35-
func (b *arrayQueryBuilder) AllUint(key string, values ...uint) *Builder {
34+
// AllFloat32 appends an element with '$all' key and given value to the builder's data slice.
35+
func (b *arrayQueryBuilder) AllFloat32(key string, values ...float32) *Builder {
3636
e := bson.E{Key: AllOp, Value: values}
3737
if !b.parent.tryMergeValue(key, e) {
3838
b.parent.data = append(b.parent.data, bson.E{Key: key, Value: bson.D{e}})
3939
}
4040
return b.parent
4141
}
4242

43-
// AllUint8 appends an element with '$all' key and given value to the builder's data slice.
44-
func (b *arrayQueryBuilder) AllUint8(key string, values ...uint8) *Builder {
43+
// AllFloat64 appends an element with '$all' key and given value to the builder's data slice.
44+
func (b *arrayQueryBuilder) AllFloat64(key string, values ...float64) *Builder {
4545
e := bson.E{Key: AllOp, Value: values}
4646
if !b.parent.tryMergeValue(key, e) {
4747
b.parent.data = append(b.parent.data, bson.E{Key: key, Value: bson.D{e}})
4848
}
4949
return b.parent
5050
}
5151

52-
// AllUint16 appends an element with '$all' key and given value to the builder's data slice.
53-
func (b *arrayQueryBuilder) AllUint16(key string, values ...uint16) *Builder {
52+
// AllInt appends an element with '$all' key and given value to the builder's data slice.
53+
func (b *arrayQueryBuilder) AllInt(key string, values ...int) *Builder {
5454
e := bson.E{Key: AllOp, Value: values}
5555
if !b.parent.tryMergeValue(key, e) {
5656
b.parent.data = append(b.parent.data, bson.E{Key: key, Value: bson.D{e}})
5757
}
5858
return b.parent
5959
}
6060

61-
// AllUint32 appends an element with '$all' key and given value to the builder's data slice.
62-
func (b *arrayQueryBuilder) AllUint32(key string, values ...uint32) *Builder {
61+
// AllInt8 appends an element with '$all' key and given value to the builder's data slice.
62+
func (b *arrayQueryBuilder) AllInt8(key string, values ...int8) *Builder {
6363
e := bson.E{Key: AllOp, Value: values}
6464
if !b.parent.tryMergeValue(key, e) {
6565
b.parent.data = append(b.parent.data, bson.E{Key: key, Value: bson.D{e}})
6666
}
6767
return b.parent
6868
}
6969

70-
// AllUint64 appends an element with '$all' key and given value to the builder's data slice.
71-
func (b *arrayQueryBuilder) AllUint64(key string, values ...uint64) *Builder {
70+
// AllInt16 appends an element with '$all' key and given value to the builder's data slice.
71+
func (b *arrayQueryBuilder) AllInt16(key string, values ...int16) *Builder {
7272
e := bson.E{Key: AllOp, Value: values}
7373
if !b.parent.tryMergeValue(key, e) {
7474
b.parent.data = append(b.parent.data, bson.E{Key: key, Value: bson.D{e}})
7575
}
7676
return b.parent
7777
}
7878

79-
// AllInt appends an element with '$all' key and given value to the builder's data slice.
80-
func (b *arrayQueryBuilder) AllInt(key string, values ...int) *Builder {
79+
// AllInt32 appends an element with '$all' key and given value to the builder's data slice.
80+
func (b *arrayQueryBuilder) AllInt32(key string, values ...int32) *Builder {
8181
e := bson.E{Key: AllOp, Value: values}
8282
if !b.parent.tryMergeValue(key, e) {
8383
b.parent.data = append(b.parent.data, bson.E{Key: key, Value: bson.D{e}})
8484
}
8585
return b.parent
8686
}
8787

88-
// AllInt8 appends an element with '$all' key and given value to the builder's data slice.
89-
func (b *arrayQueryBuilder) AllInt8(key string, values ...int8) *Builder {
88+
// AllInt64 appends an element with '$all' key and given value to the builder's data slice.
89+
func (b *arrayQueryBuilder) AllInt64(key string, values ...int64) *Builder {
9090
e := bson.E{Key: AllOp, Value: values}
9191
if !b.parent.tryMergeValue(key, e) {
9292
b.parent.data = append(b.parent.data, bson.E{Key: key, Value: bson.D{e}})
9393
}
9494
return b.parent
9595
}
9696

97-
// AllInt16 appends an element with '$all' key and given value to the builder's data slice.
98-
func (b *arrayQueryBuilder) AllInt16(key string, values ...int16) *Builder {
97+
// AllString appends an element with '$all' key and given value to the builder's data slice.
98+
func (b *arrayQueryBuilder) AllString(key string, values ...string) *Builder {
9999
e := bson.E{Key: AllOp, Value: values}
100100
if !b.parent.tryMergeValue(key, e) {
101101
b.parent.data = append(b.parent.data, bson.E{Key: key, Value: bson.D{e}})
102102
}
103103
return b.parent
104104
}
105105

106-
// AllInt32 appends an element with '$all' key and given value to the builder's data slice.
107-
func (b *arrayQueryBuilder) AllInt32(key string, values ...int32) *Builder {
106+
// AllUint appends an element with '$all' key and given value to the builder's data slice.
107+
func (b *arrayQueryBuilder) AllUint(key string, values ...uint) *Builder {
108108
e := bson.E{Key: AllOp, Value: values}
109109
if !b.parent.tryMergeValue(key, e) {
110110
b.parent.data = append(b.parent.data, bson.E{Key: key, Value: bson.D{e}})
111111
}
112112
return b.parent
113113
}
114114

115-
// AllInt64 appends an element with '$all' key and given value to the builder's data slice.
116-
func (b *arrayQueryBuilder) AllInt64(key string, values ...int64) *Builder {
115+
// AllUint8 appends an element with '$all' key and given value to the builder's data slice.
116+
func (b *arrayQueryBuilder) AllUint8(key string, values ...uint8) *Builder {
117117
e := bson.E{Key: AllOp, Value: values}
118118
if !b.parent.tryMergeValue(key, e) {
119119
b.parent.data = append(b.parent.data, bson.E{Key: key, Value: bson.D{e}})
120120
}
121121
return b.parent
122122
}
123123

124-
// AllString appends an element with '$all' key and given value to the builder's data slice.
125-
func (b *arrayQueryBuilder) AllString(key string, values ...string) *Builder {
124+
// AllUint16 appends an element with '$all' key and given value to the builder's data slice.
125+
func (b *arrayQueryBuilder) AllUint16(key string, values ...uint16) *Builder {
126126
e := bson.E{Key: AllOp, Value: values}
127127
if !b.parent.tryMergeValue(key, e) {
128128
b.parent.data = append(b.parent.data, bson.E{Key: key, Value: bson.D{e}})
129129
}
130130
return b.parent
131131
}
132132

133-
// AllFloat32 appends an element with '$all' key and given value to the builder's data slice.
134-
func (b *arrayQueryBuilder) AllFloat32(key string, values ...float32) *Builder {
133+
// AllUint32 appends an element with '$all' key and given value to the builder's data slice.
134+
func (b *arrayQueryBuilder) AllUint32(key string, values ...uint32) *Builder {
135135
e := bson.E{Key: AllOp, Value: values}
136136
if !b.parent.tryMergeValue(key, e) {
137137
b.parent.data = append(b.parent.data, bson.E{Key: key, Value: bson.D{e}})
138138
}
139139
return b.parent
140140
}
141141

142-
// AllFloat64 appends an element with '$all' key and given value to the builder's data slice.
143-
func (b *arrayQueryBuilder) AllFloat64(key string, values ...float64) *Builder {
142+
// AllUint64 appends an element with '$all' key and given value to the builder's data slice.
143+
func (b *arrayQueryBuilder) AllUint64(key string, values ...uint64) *Builder {
144144
e := bson.E{Key: AllOp, Value: values}
145145
if !b.parent.tryMergeValue(key, e) {
146146
b.parent.data = append(b.parent.data, bson.E{Key: key, Value: bson.D{e}})

builder/query/bson_build.go

Lines changed: 50 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -19,26 +19,30 @@ import (
1919
"go.mongodb.org/mongo-driver/bson/bsontype"
2020
)
2121

22-
func Id(value any) bson.D {
23-
return bson.D{bson.E{Key: IdOp, Value: value}}
24-
}
25-
2622
func All[T any](values ...T) bson.D {
2723
return bson.D{bson.E{Key: AllOp, Value: values}}
2824
}
2925

30-
func ElemMatch(key string, cond any) bson.D {
31-
return bson.D{bson.E{Key: key, Value: bson.D{{Key: ElemMatchOp, Value: cond}}}}
26+
func And(conditions ...any) bson.D {
27+
return bson.D{bson.E{Key: AndOp, Value: conditions}}
3228
}
3329

34-
func Size(key string, value int) bson.D {
35-
return bson.D{bson.E{Key: key, Value: bson.D{{Key: SizeOp, Value: value}}}}
30+
func ElemMatch(key string, cond any) bson.D {
31+
return bson.D{bson.E{Key: key, Value: bson.D{{Key: ElemMatchOp, Value: cond}}}}
3632
}
3733

3834
func Eq(key string, value any) bson.D {
3935
return bson.D{bson.E{Key: key, Value: bson.D{{Key: EqOp, Value: value}}}}
4036
}
4137

38+
func Exists(key string, value bool) bson.D {
39+
return bson.D{bson.E{Key: key, Value: bson.D{{Key: ExistsOp, Value: value}}}}
40+
}
41+
42+
func Expr(value any) bson.D {
43+
return bson.D{bson.E{Key: ExprOp, Value: value}}
44+
}
45+
4246
func Gt(key string, value any) bson.D {
4347
return bson.D{bson.E{Key: key, Value: bson.D{{Key: GtOp, Value: value}}}}
4448
}
@@ -47,12 +51,16 @@ func Gte(key string, value any) bson.D {
4751
return bson.D{bson.E{Key: key, Value: bson.D{{Key: GteOp, Value: value}}}}
4852
}
4953

54+
func Id(value any) bson.D {
55+
return bson.D{bson.E{Key: IdOp, Value: value}}
56+
}
57+
5058
func In[T any](key string, values ...T) bson.D {
5159
return bson.D{bson.E{Key: key, Value: bson.D{{Key: InOp, Value: values}}}}
5260
}
5361

54-
func NIn[T any](key string, values ...T) bson.D {
55-
return bson.D{bson.E{Key: key, Value: bson.D{{Key: NinOp, Value: values}}}}
62+
func JsonSchema(value any) bson.D {
63+
return bson.D{bson.E{Key: JsonSchemaOp, Value: value}}
5664
}
5765

5866
func Lt(key string, value any) bson.D {
@@ -63,48 +71,48 @@ func Lte(key string, value any) bson.D {
6371
return bson.D{bson.E{Key: key, Value: bson.D{{Key: LteOp, Value: value}}}}
6472
}
6573

66-
func Ne(key string, value any) bson.D {
67-
return bson.D{bson.E{Key: key, Value: bson.D{{Key: NeOp, Value: value}}}}
74+
func Mod(key string, divisor any, remainder int) bson.D {
75+
return bson.D{bson.E{Key: key, Value: bson.D{{Key: ModOp, Value: bson.A{divisor, remainder}}}}}
6876
}
6977

70-
func Exists(key string, value bool) bson.D {
71-
return bson.D{bson.E{Key: key, Value: bson.D{{Key: ExistsOp, Value: value}}}}
78+
func NIn[T any](key string, values ...T) bson.D {
79+
return bson.D{bson.E{Key: key, Value: bson.D{{Key: NinOp, Value: values}}}}
7280
}
7381

74-
func Type(key string, value bsontype.Type) bson.D {
75-
return bson.D{bson.E{Key: key, Value: bson.D{{Key: TypeOp, Value: value}}}}
82+
func Ne(key string, value any) bson.D {
83+
return bson.D{bson.E{Key: key, Value: bson.D{{Key: NeOp, Value: value}}}}
7684
}
7785

78-
func TypeAlias(key string, value string) bson.D {
79-
return bson.D{bson.E{Key: key, Value: bson.D{{Key: TypeOp, Value: value}}}}
86+
func Nor(conditions ...any) bson.D {
87+
return bson.D{bson.E{Key: NorOp, Value: conditions}}
8088
}
8189

82-
func TypeArray(key string, values ...bsontype.Type) bson.D {
83-
return bson.D{bson.E{Key: key, Value: bson.D{{Key: TypeOp, Value: values}}}}
90+
func Not(cond any) bson.D {
91+
return bson.D{bson.E{Key: NotOp, Value: cond}}
8492
}
8593

86-
func TypeArrayAlias(key string, values ...string) bson.D {
87-
return bson.D{bson.E{Key: key, Value: bson.D{{Key: TypeOp, Value: values}}}}
94+
func Or(conditions ...any) bson.D {
95+
return bson.D{bson.E{Key: OrOp, Value: conditions}}
8896
}
8997

90-
func Expr(value any) bson.D {
91-
return bson.D{bson.E{Key: ExprOp, Value: value}}
98+
func Regex(key, value string) bson.D {
99+
return bson.D{bson.E{Key: key, Value: bson.D{{Key: RegexOp, Value: value}}}}
92100
}
93101

94-
func JsonSchema(value any) bson.D {
95-
return bson.D{bson.E{Key: JsonSchemaOp, Value: value}}
102+
func RegexOptions(key, value, options string) bson.D {
103+
return bson.D{bson.E{Key: key, Value: bson.D{{Key: RegexOp, Value: value}, {Key: OptionsOp, Value: options}}}}
96104
}
97105

98-
func Mod(key string, divisor any, remainder int) bson.D {
99-
return bson.D{bson.E{Key: key, Value: bson.D{{Key: ModOp, Value: bson.A{divisor, remainder}}}}}
106+
func Size(key string, value int) bson.D {
107+
return bson.D{bson.E{Key: key, Value: bson.D{{Key: SizeOp, Value: value}}}}
100108
}
101109

102-
func Regex(key, value string) bson.D {
103-
return bson.D{bson.E{Key: key, Value: bson.D{{Key: RegexOp, Value: value}}}}
110+
func Slice(key string, number int) bson.D {
111+
return bson.D{bson.E{Key: key, Value: bson.D{{Key: SliceOp, Value: number}}}}
104112
}
105113

106-
func RegexOptions(key, value, options string) bson.D {
107-
return bson.D{bson.E{Key: key, Value: bson.D{{Key: RegexOp, Value: value}, {Key: OptionsOp, Value: options}}}}
114+
func SliceRanger(key string, start, end int) bson.D {
115+
return bson.D{bson.E{Key: key, Value: bson.D{{Key: SliceOp, Value: []int{start, end}}}}}
108116
}
109117

110118
func Text(search string, opt *TextOptions) bson.D {
@@ -124,30 +132,22 @@ func Text(search string, opt *TextOptions) bson.D {
124132
return bson.D{bson.E{Key: TextOp, Value: d}}
125133
}
126134

127-
func Where(value string) bson.D {
128-
return bson.D{bson.E{Key: WhereOp, Value: value}}
129-
}
130-
131-
func And(conditions ...any) bson.D {
132-
return bson.D{bson.E{Key: AndOp, Value: conditions}}
133-
}
134-
135-
func Not(cond any) bson.D {
136-
return bson.D{bson.E{Key: NotOp, Value: cond}}
135+
func Type(key string, value bsontype.Type) bson.D {
136+
return bson.D{bson.E{Key: key, Value: bson.D{{Key: TypeOp, Value: value}}}}
137137
}
138138

139-
func Nor(conditions ...any) bson.D {
140-
return bson.D{bson.E{Key: NorOp, Value: conditions}}
139+
func TypeAlias(key string, value string) bson.D {
140+
return bson.D{bson.E{Key: key, Value: bson.D{{Key: TypeOp, Value: value}}}}
141141
}
142142

143-
func Or(conditions ...any) bson.D {
144-
return bson.D{bson.E{Key: OrOp, Value: conditions}}
143+
func TypeArray(key string, values ...bsontype.Type) bson.D {
144+
return bson.D{bson.E{Key: key, Value: bson.D{{Key: TypeOp, Value: values}}}}
145145
}
146146

147-
func Slice(key string, number int) bson.D {
148-
return bson.D{bson.E{Key: key, Value: bson.D{{Key: SliceOp, Value: number}}}}
147+
func TypeArrayAlias(key string, values ...string) bson.D {
148+
return bson.D{bson.E{Key: key, Value: bson.D{{Key: TypeOp, Value: values}}}}
149149
}
150150

151-
func SliceRanger(key string, start, end int) bson.D {
152-
return bson.D{bson.E{Key: key, Value: bson.D{{Key: SliceOp, Value: []int{start, end}}}}}
151+
func Where(value string) bson.D {
152+
return bson.D{bson.E{Key: WhereOp, Value: value}}
153153
}

0 commit comments

Comments
 (0)