Skip to content

Commit

Permalink
Adopt to mongo-driver v1.11.x (#81)
Browse files Browse the repository at this point in the history
* add Timeout function to Client
* regenerate the mocks
  • Loading branch information
SVilgelm committed Feb 5, 2023
1 parent b1965d3 commit c8b04fb
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 9 deletions.
6 changes: 6 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package mongoifc

import (
"context"
"time"

"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
Expand All @@ -23,6 +24,7 @@ type Client interface {
NumberSessionsInProgress() int
Ping(ctx context.Context, rp *readpref.ReadPref) error
StartSession(opts ...*options.SessionOptions) (Session, error)
Timeout() *time.Duration
UseSession(ctx context.Context, fn func(sc SessionContext) error) error
UseSessionWithOptions(ctx context.Context, opts *options.SessionOptions, fn func(sc SessionContext) error) error
Watch(
Expand Down Expand Up @@ -81,6 +83,10 @@ func (c *client) StartSession(opts ...*options.SessionOptions) (Session, error)
return wrapSession(ss, c), nil
}

func (c *client) Timeout() *time.Duration {
return c.cl.Timeout()
}

func (c *client) UseSession(ctx context.Context, fn func(sc SessionContext) error) error {
return c.cl.UseSession(ctx, wrapFn1(fn, c))
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/sv-tools/mongoifc

go 1.19
go 1.20

require (
github.com/golang/mock v1.6.0
Expand Down
14 changes: 14 additions & 0 deletions mocks/gomock/mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions mocks/mockery/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 16 additions & 8 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,29 @@ import (
// Session is an interface for `mongo.Session` structure
// Documentation: https://pkg.go.dev/go.mongodb.org/mongo-driver/mongo#Session
type Session interface {
// Functions to modify session state.

StartTransaction(opts ...*options.TransactionOptions) error
AbortTransaction(ctx context.Context) error
AdvanceClusterTime(bson.Raw) error
AdvanceOperationTime(*primitive.Timestamp) error
Client() Client
ClusterTime() bson.Raw
CommitTransaction(ctx context.Context) error
EndSession(ctx context.Context)
ID() bson.Raw
OperationTime() *primitive.Timestamp
StartTransaction(opts ...*options.TransactionOptions) error
WithTransaction(
ctx context.Context,
fn func(sc SessionContext) (interface{}, error),
opts ...*options.TransactionOptions,
) (interface{}, error)
EndSession(ctx context.Context)

// Functions to retrieve session properties.

ClusterTime() bson.Raw
OperationTime() *primitive.Timestamp
Client() Client
ID() bson.Raw

// Functions to modify mutable session properties.

AdvanceClusterTime(bson.Raw) error
AdvanceOperationTime(*primitive.Timestamp) error
}

type session struct {
Expand Down

0 comments on commit c8b04fb

Please sign in to comment.