-
Notifications
You must be signed in to change notification settings - Fork 2
/
wrapped_database.go
64 lines (46 loc) · 1.67 KB
/
wrapped_database.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
package gomongowrapper
import (
"context"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"go.mongodb.org/mongo-driver/mongo/readconcern"
"go.mongodb.org/mongo-driver/mongo/readpref"
"go.mongodb.org/mongo-driver/mongo/writeconcern"
tracewrap "github.com/opencensus-integrations/gomongowrapper"
)
type Database struct {
db *tracewrap.WrappedDatabase
}
func (wd *Database) Client() *Client {
cc := wd.db.Client()
if cc == nil {
return nil
}
return &Client{cc: cc}
}
func (wd *Database) Collection(name string, opts ...*options.CollectionOptions) *Collection {
if wd.db == nil {
return nil
}
coll := wd.db.Collection(name, opts...)
if coll == nil {
return nil
}
return &Collection{coll: coll}
}
func (wd *Database) Drop(ctx context.Context) error {
return handle(wd.db.Drop(ctx))
}
func (wd *Database) ListCollections(ctx context.Context, filter interface{}, opts ...*options.ListCollectionsOptions) (*mongo.Cursor, error) {
cur, err := wd.db.ListCollections(ctx, filter, opts...)
return cur, handle(err)
}
func (wd *Database) Name() string { return wd.db.Name() }
func (wd *Database) ReadConcern() *readconcern.ReadConcern { return wd.db.ReadConcern() }
func (wd *Database) ReadPreference() *readpref.ReadPref { return wd.db.ReadPreference() }
func (wd *Database) RunCommand(ctx context.Context, runCommand interface{}, opts ...*options.RunCmdOptions) *mongo.SingleResult {
res := wd.db.RunCommand(ctx, runCommand, opts...)
return res
}
func (wd *Database) WriteConcern() *writeconcern.WriteConcern { return wd.db.WriteConcern() }
func (wd *Database) Database() *mongo.Database { return wd.db.Database() }