bumps our uptrace/bun dependencies to v1.2.10 (#3865)

This commit is contained in:
kim 2025-03-03 10:42:05 +00:00 committed by GitHub
commit 67a2b3650c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
37 changed files with 518 additions and 225 deletions

View file

@ -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)
}
}