summaryrefslogtreecommitdiff
path: root/vendor/github.com/uptrace/bun/util.go
diff options
context:
space:
mode:
authorLibravatar kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com>2025-03-03 10:42:05 +0000
committerLibravatar GitHub <noreply@github.com>2025-03-03 10:42:05 +0000
commit67a2b3650c5f586431c8559bc9b609699de8431d (patch)
treef4a269939f7f175277a92aaa33bf58e652d4e276 /vendor/github.com/uptrace/bun/util.go
parent[chore]: Bump github.com/prometheus/client_golang from 1.20.5 to 1.21.0 (#3860) (diff)
downloadgotosocial-67a2b3650c5f586431c8559bc9b609699de8431d.tar.xz
bumps our uptrace/bun dependencies to v1.2.10 (#3865)
Diffstat (limited to 'vendor/github.com/uptrace/bun/util.go')
-rw-r--r--vendor/github.com/uptrace/bun/util.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/vendor/github.com/uptrace/bun/util.go b/vendor/github.com/uptrace/bun/util.go
index 97ed9228a..cffcfab45 100644
--- a/vendor/github.com/uptrace/bun/util.go
+++ b/vendor/github.com/uptrace/bun/util.go
@@ -1,6 +1,7 @@
package bun
import (
+ "context"
"fmt"
"reflect"
"strings"
@@ -86,3 +87,26 @@ func appendComment(b []byte, name string) []byte {
name = strings.ReplaceAll(name, `*/`, `*\/`)
return append(b, fmt.Sprintf("/* %s */ ", name)...)
}
+
+// queryCommentCtxKey is a context key for setting a query comment on a context instead of calling the Comment("...") API directly
+type queryCommentCtxKey struct{}
+
+// WithComment returns a context that includes a comment that may be included in a query for debugging
+//
+// If a context with an attached query is used, a comment set by the Comment("...") API will be overwritten.
+func WithComment(ctx context.Context, comment string) context.Context {
+ return context.WithValue(ctx, queryCommentCtxKey{}, comment)
+}
+
+// commenter describes the Comment interface implemented by all of the query types
+type commenter[T any] interface {
+ Comment(string) T
+}
+
+// setCommentFromContext sets the comment on the given query from the supplied context if one is set using the Comment(...) method.
+func setCommentFromContext[T any](ctx context.Context, q commenter[T]) {
+ s, _ := ctx.Value(queryCommentCtxKey{}).(string)
+ if s != "" {
+ q.Comment(s)
+ }
+}