-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquery_builder.go
More file actions
65 lines (52 loc) · 890 Bytes
/
query_builder.go
File metadata and controls
65 lines (52 loc) · 890 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package mongodata
import (
"strings"
"go.mongodb.org/mongo-driver/bson"
)
type QueryBuilder struct {
Filter FilterBuilder
Sort SortBuilder
}
func Query(
filter FilterBuilder,
sort SortBuilder,
) QueryBuilder {
return QueryBuilder{
Filter: filter,
Sort: sort,
}
}
type QueryType interface {
Filter() map[string]any
Sort() map[string]Sort
Projection() map[string]Projection
Offset() int
Limit() int
}
func Field(names ...string) string {
return strings.Join(names, ".")
}
type elementA interface {
build() bson.A
}
type elementD interface {
build() bson.D
}
type elementE interface {
build() bson.E
}
type elementM interface {
build() bson.M
}
func a(values ...any) bson.A {
return bson.A(values)
}
func d(elements ...bson.E) bson.D {
return bson.D(elements)
}
func e(key string, value any) bson.E {
return bson.E{
Key: key,
Value: value,
}
}