-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathchange_stream.go
More file actions
79 lines (64 loc) · 2.07 KB
/
change_stream.go
File metadata and controls
79 lines (64 loc) · 2.07 KB
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
package mongoifc
import (
"context"
"go.mongodb.org/mongo-driver/v2/bson"
"go.mongodb.org/mongo-driver/v2/mongo"
)
// ChangeStream is an interface for `mongo.ChangeStream` structure
// Documentation: https://pkg.go.dev/go.mongodb.org/mongo-driver/v2/mongo#ChangeStream
type ChangeStream interface {
Current() bson.Raw
Close(ctx context.Context) error
Decode(val any) error
Err() error
ID() int64
Next(ctx context.Context) bool
RemainingBatchLength() int
ResumeToken() bson.Raw
SetBatchSize(size int32)
TryNext(ctx context.Context) bool
}
type changeStream struct {
cs *mongo.ChangeStream
}
// Current is a wrapper for `mongo.ChangeStream.Current` field
func (c *changeStream) Current() bson.Raw {
return c.cs.Current
}
// Close is a wrapper for `mongo.ChangeStream.Close` method
func (c *changeStream) Close(ctx context.Context) error {
return c.cs.Close(ctx)
}
// Decode is a wrapper for `mongo.ChangeStream.Decode` method
func (c *changeStream) Decode(val any) error {
return c.cs.Decode(val)
}
// Err is a wrapper for `mongo.ChangeStream.Err` method
func (c *changeStream) Err() error {
return c.cs.Err()
}
// ID is a wrapper for `mongo.ChangeStream.ID` method
func (c *changeStream) ID() int64 {
return c.cs.ID()
}
// Next is a wrapper for `mongo.ChangeStream.Next` method
func (c *changeStream) Next(ctx context.Context) bool {
return c.cs.Next(ctx)
}
// RemainingBatchLength is a wrapper for `mongo.ChangeStream.RemainingBatchLength` method
func (c *changeStream) RemainingBatchLength() int { return c.cs.RemainingBatchLength() }
// ResumeToken is a wrapper for `mongo.ChangeStream.ResumeToken` method
func (c *changeStream) ResumeToken() bson.Raw {
return c.cs.ResumeToken()
}
// SetBatchSize is a wrapper for `mongo.ChangeStream.SetBatchSize` method
func (c *changeStream) SetBatchSize(size int32) {
c.cs.SetBatchSize(size)
}
// TryNext is a wrapper for `mongo.ChangeStream.TryNext` method
func (c *changeStream) TryNext(ctx context.Context) bool {
return c.cs.TryNext(ctx)
}
func wrapChangeStream(cs *mongo.ChangeStream) ChangeStream {
return &changeStream{cs: cs}
}