-
Notifications
You must be signed in to change notification settings - Fork 0
/
session.go
38 lines (28 loc) · 821 Bytes
/
session.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
package dbm
import (
"context"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
type SessionOptions = options.SessionOptions
func NewSessionOptions() *SessionOptions {
return options.Session()
}
type TransactionOptions = options.TransactionOptions
func NewTransactionOptions() *TransactionOptions {
return options.Transaction()
}
type SessionContext = mongo.SessionContext
type Session interface {
mongo.Session
BeginTx(ctx context.Context, opts ...*TransactionOptions) (Tx, error)
}
type session struct {
mongo.Session
}
func (s *session) BeginTx(ctx context.Context, opts ...*TransactionOptions) (Tx, error) {
if err := s.Session.StartTransaction(opts...); err != nil {
return nil, err
}
return &transaction{mongo.NewSessionContext(ctx, s.Session), false}, nil
}