Skip to content

Commit

Permalink
pgctx: add GetDB and GetDBKey
Browse files Browse the repository at this point in the history
  • Loading branch information
acoshift committed Dec 21, 2022
1 parent 687443f commit 26d9674
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pgctx/pgctx.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ func With(ctx context.Context, key any) context.Context {
return context.WithValue(ctx, ctxKeyDB{}, db)
}

func GetDB(ctx context.Context) DB {
return ctx.Value(ctxKeyDB{}).(DB)
}

func GetDBKey(ctx context.Context, key any) DB {
return ctx.Value(ctxKeyDB{key}).(DB)
}

type wrapTx struct {
*sql.Tx
onCommitted []func(ctx context.Context)
Expand Down Expand Up @@ -114,7 +122,7 @@ func Committed(ctx context.Context, f func(ctx context.Context)) {
}

type (
ctxKeyDB struct{
ctxKeyDB struct {
key any
}
ctxKeyQueryer struct{}
Expand Down

0 comments on commit 26d9674

Please sign in to comment.