Skip to content

Commit 8da6da7

Browse files
committed
added db.IsTransaction
1 parent 7a8869d commit 8da6da7

File tree

2 files changed

+6
-19
lines changed

2 files changed

+6
-19
lines changed

db/conn.go

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ package db
22

33
import (
44
"context"
5-
"fmt"
6-
"time"
75

86
"github.com/domonda/go-sqldb"
97
)
@@ -48,21 +46,9 @@ func ContextWithConn(ctx context.Context, conn sqldb.Connection) context.Context
4846
return context.WithValue(ctx, &globalConnCtxKey, conn)
4947
}
5048

51-
// ContextWithoutCancel returns a new context that inherits
52-
// all values from parent, but not its cancellation state.
53-
func ContextWithoutCancel(parent context.Context) context.Context {
54-
if _, ok := parent.(contextWithoutCancel); ok {
55-
return parent
56-
}
57-
return contextWithoutCancel{parent}
58-
}
59-
60-
type contextWithoutCancel struct {
61-
parent context.Context
49+
// IsTransaction indicates if the connection from the context,
50+
// or the default connection if the context has none,
51+
// is a transaction.
52+
func IsTransaction(ctx context.Context) bool {
53+
return Conn(ctx).IsTransaction()
6254
}
63-
64-
func (contextWithoutCancel) Deadline() (time.Time, bool) { return time.Time{}, false }
65-
func (contextWithoutCancel) Done() <-chan struct{} { return nil }
66-
func (contextWithoutCancel) Err() error { return nil }
67-
func (c contextWithoutCancel) Value(key any) any { return c.parent.Value(key) }
68-
func (c contextWithoutCancel) String() string { return fmt.Sprintf("%s.WithoutCancel", c.parent) }

go.work.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ github.com/teamwork/tnef v0.0.0-20200108124832-7deabccfdb32 h1:j15wq0XPAY/HR/0+d
2424
github.com/teamwork/tnef v0.0.0-20200108124832-7deabccfdb32/go.mod h1:v7dFaQrF/4+curx7UTH9rqTkHTgXqghfI3thANW150o=
2525
github.com/teamwork/utils v0.0.0-20220314153103-637fa45fa6cc/go.mod h1:3Fn0qxFeRNpvsg/9T1+btOOOKkd1qG2nPYKKcOmNpcs=
2626
github.com/ungerik/go-fs v0.0.0-20230206141012-abb864f815e3 h1:IEm9Je1L3HAIEwiXOuGgJuUPjXXHzf/1e704VyIbcGc=
27+
github.com/ungerik/go-fs v0.0.0-20230810132455-f7ff27f6fa2b h1:hZ/Tp1sn1oRwYqIZfjpfUp8N+5e3LGk32O8OAMh9VOk=
2728
github.com/ungerik/go-fs v0.0.0-20230810132455-f7ff27f6fa2b/go.mod h1:P8k1DG+Ox0KP4MFNTSPd8ojoDUwXjrWdGjsssF6vT/g=
2829
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
2930
golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw=

0 commit comments

Comments
 (0)