generated from sv-tools/go-repo-template
-
Notifications
You must be signed in to change notification settings - Fork 4
/
change_stream.go
66 lines (52 loc) · 1.32 KB
/
change_stream.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
package mongoifc
import (
"context"
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
)
// ChangeStream is an interface for `mongo.ChangeStream` structure
// Documentation: https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#ChangeStream
type ChangeStream interface {
Current() bson.Raw
Close(ctx context.Context) error
Decode(val interface{}) error
Err() error
ID() int64
Next(ctx context.Context) bool
ResumeToken() bson.Raw
SetBatchSize(size int32)
TryNext(ctx context.Context) bool
}
type changeStream struct {
cs *mongo.ChangeStream
}
func (c *changeStream) Current() bson.Raw {
return c.cs.Current
}
func (c *changeStream) Close(ctx context.Context) error {
return c.cs.Close(ctx)
}
func (c *changeStream) Decode(val interface{}) error {
return c.cs.Decode(val)
}
func (c *changeStream) Err() error {
return c.cs.Err()
}
func (c *changeStream) ID() int64 {
return c.cs.ID()
}
func (c *changeStream) Next(ctx context.Context) bool {
return c.cs.Next(ctx)
}
func (c *changeStream) ResumeToken() bson.Raw {
return c.cs.ResumeToken()
}
func (c *changeStream) SetBatchSize(size int32) {
c.cs.SetBatchSize(size)
}
func (c *changeStream) TryNext(ctx context.Context) bool {
return c.cs.TryNext(ctx)
}
func wrapChangeStream(cs *mongo.ChangeStream) ChangeStream {
return &changeStream{cs: cs}
}