generated from sv-tools/go-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex_view.go
81 lines (68 loc) · 2.43 KB
/
index_view.go
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package mongoifc
import (
"context"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
// IndexView is an interface for `mongo.IndexView` structure
// Documentation: https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#IndexView
type IndexView interface {
CreateMany(ctx context.Context, models []mongo.IndexModel, opts ...*options.CreateIndexesOptions) ([]string, error)
CreateOne(ctx context.Context, model mongo.IndexModel, opts ...*options.CreateIndexesOptions) (string, error)
DropAll(ctx context.Context, opts ...*options.DropIndexesOptions) (bson.Raw, error)
DropOne(ctx context.Context, name string, opts ...*options.DropIndexesOptions) (bson.Raw, error)
DropOneWithKey(
ctx context.Context,
keySpecDocument interface{},
opts ...*options.DropIndexesOptions,
) (bson.Raw, error)
List(ctx context.Context, opts ...*options.ListIndexesOptions) (Cursor, error)
ListSpecifications(ctx context.Context, opts ...*options.ListIndexesOptions) ([]*mongo.IndexSpecification, error)
}
type indexView struct {
iv *mongo.IndexView
}
func (i *indexView) CreateMany(
ctx context.Context,
models []mongo.IndexModel,
opts ...*options.CreateIndexesOptions,
) ([]string, error) {
return i.iv.CreateMany(ctx, models, opts...)
}
func (i *indexView) CreateOne(
ctx context.Context,
model mongo.IndexModel,
opts ...*options.CreateIndexesOptions,
) (string, error) {
return i.iv.CreateOne(ctx, model, opts...)
}
func (i *indexView) DropAll(ctx context.Context, opts ...*options.DropIndexesOptions) (bson.Raw, error) {
return i.iv.DropAll(ctx, opts...)
}
func (i *indexView) DropOne(ctx context.Context, name string, opts ...*options.DropIndexesOptions) (bson.Raw, error) {
return i.iv.DropOne(ctx, name, opts...)
}
func (i *indexView) DropOneWithKey(
ctx context.Context,
keySpecDocument interface{},
opts ...*options.DropIndexesOptions,
) (bson.Raw, error) {
return i.iv.DropOneWithKey(ctx, keySpecDocument, opts...)
}
func (i *indexView) List(ctx context.Context, opts ...*options.ListIndexesOptions) (Cursor, error) {
cr, err := i.iv.List(ctx, opts...)
if err != nil {
return nil, err
}
return wrapCursor(cr), nil
}
func (i *indexView) ListSpecifications(
ctx context.Context,
opts ...*options.ListIndexesOptions,
) ([]*mongo.IndexSpecification, error) {
return i.iv.ListSpecifications(ctx, opts...)
}
func wrapIndexView(iv *mongo.IndexView) IndexView {
return &indexView{iv: iv}
}