Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(deps): bump golang.org/x/net from 0.22.0 to 0.23.0 in /example/opentelemetry #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/opentelemetry/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ require (
go.opentelemetry.io/otel/trace v1.24.0 // indirect
go.opentelemetry.io/proto/otlp v1.1.0 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.22.0 // indirect
golang.org/x/net v0.23.0 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240401170217-c3f982113cda // indirect
Expand Down
4 changes: 2 additions & 2 deletions example/opentelemetry/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA=
golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs=
golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc=
golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/net v0.23.0 h1:7EYJ93RZ9vYSZAIb2x3lnuvqO5zneoD6IvWjuhfxjTs=
golang.org/x/net v0.23.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
Expand Down
10 changes: 5 additions & 5 deletions internal/dbtest/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ require (
github.com/denisenkom/go-mssqldb v0.12.2
github.com/go-sql-driver/mysql v1.6.0
github.com/google/uuid v1.6.0
github.com/jackc/pgx/v4 v4.11.0
github.com/jackc/pgx/v4 v4.18.2
github.com/stretchr/testify v1.8.1
github.com/uptrace/bun v1.2.1
github.com/uptrace/bun/dbfixture v1.2.1
Expand All @@ -49,12 +49,12 @@ require (
github.com/golang-sql/sqlexp v0.1.0 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.8.1 // indirect
github.com/jackc/pgconn v1.14.3 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.0.6 // indirect
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
github.com/jackc/pgtype v1.7.0 // indirect
github.com/jackc/pgproto3/v2 v2.3.3 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgtype v1.14.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
Expand Down
359 changes: 35 additions & 324 deletions internal/dbtest/go.sum

Large diffs are not rendered by default.

43 changes: 43 additions & 0 deletions query_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ var (
// QueryBuilder is used for common query methods
type QueryBuilder interface {
Query
Comment(c string) QueryBuilder
Where(query string, args ...interface{}) QueryBuilder
WhereGroup(sep string, fn func(QueryBuilder) QueryBuilder) QueryBuilder
WhereOr(query string, args ...interface{}) QueryBuilder
Expand Down Expand Up @@ -104,6 +105,8 @@ type baseQuery struct {
tables []schema.QueryWithArgs
columns []schema.QueryWithArgs

comment string

flags internal.Flag
}

Expand Down Expand Up @@ -146,6 +149,32 @@ func (q *baseQuery) GetTableName() string {
return ""
}

func (q *baseQuery) setComment(c string) {
q.comment = c
}

func (q *baseQuery) appendComment(b []byte) []byte {
if len(q.comment) < 1 {
return b
}

lastIdx := len(q.comment) - 1
b = append(b, "/*"...)
for i := range q.comment {
// if the comment contains the closing sequence, escape it
if q.comment[i] == '*' && i < lastIdx && q.comment[i] == '/' {
b = append(b, '\\')
b = append(b, q.comment[i])
b = append(b, '\\')
} else {
b = append(b, q.comment[i])
}
}
b = append(b, "*/ "...)

return b
}

func (q *baseQuery) setConn(db IConn) {
// Unwrap Bun wrappers to not call query hooks twice.
switch db := db.(type) {
Expand Down Expand Up @@ -1347,3 +1376,17 @@ func (ih *idxHintsQuery) bufIndexHint(
b = append(b, ")"...)
return b, nil
}

//------------------------------------------------------------------------------

type queryCommentCtxKey struct{}

// CtxWithComment returns a context that includes a comment that may be included in a query for debugging
func ContextWithComment(ctx context.Context, comment string) context.Context {
return context.WithValue(ctx, queryCommentCtxKey{}, comment)
}

func commentFromContext(ctx context.Context) string {
c, _ := ctx.Value(queryCommentCtxKey{}).(string)
return c
}
18 changes: 17 additions & 1 deletion query_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ func (q *DeleteQuery) Err(err error) *DeleteQuery {
return q
}

// Comment prepends a comment to the beginning of the query.
// This is useful for debugging or identifying queries in database logs.
func (q *DeleteQuery) Comment(c string) *DeleteQuery {
q.setComment(c)
return q
}

// Apply calls the fn passing the DeleteQuery as an argument.
func (q *DeleteQuery) Apply(fn func(*DeleteQuery) *DeleteQuery) *DeleteQuery {
if fn != nil {
Expand Down Expand Up @@ -259,8 +266,10 @@ func (q *DeleteQuery) scanOrExec(
return nil, err
}

q.setComment(commentFromContext(ctx))

// Generate the query before checking hasReturning.
queryBytes, err := q.AppendQuery(q.db.fmter, q.db.makeQueryBytes())
queryBytes, err := q.AppendQuery(q.db.fmter, q.appendComment(q.db.makeQueryBytes()))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -342,6 +351,13 @@ type deleteQueryBuilder struct {
*DeleteQuery
}

// Comment prepends a comment to the beginning of the query.
// This is useful for debugging or identifying queries in database logs.
func (q *deleteQueryBuilder) Comment(c string) QueryBuilder {
q.setComment(c)
return q
}

func (q *deleteQueryBuilder) WhereGroup(
sep string, fn func(QueryBuilder) QueryBuilder,
) QueryBuilder {
Expand Down
11 changes: 10 additions & 1 deletion query_insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ func (q *InsertQuery) Err(err error) *InsertQuery {
return q
}

// Comment prepends a comment to the beginning of the query.
// This is useful for debugging or identifying queries in database logs.
func (q *InsertQuery) Comment(c string) *InsertQuery {
q.setComment(c)
return q
}

// Apply calls the fn passing the SelectQuery as an argument.
func (q *InsertQuery) Apply(fn func(*InsertQuery) *InsertQuery) *InsertQuery {
if fn != nil {
Expand Down Expand Up @@ -574,8 +581,10 @@ func (q *InsertQuery) scanOrExec(
return nil, err
}

q.setComment(commentFromContext(ctx))

// Generate the query before checking hasReturning.
queryBytes, err := q.AppendQuery(q.db.fmter, q.db.makeQueryBytes())
queryBytes, err := q.AppendQuery(q.db.fmter, q.appendComment(q.db.makeQueryBytes()))
if err != nil {
return nil, err
}
Expand Down
11 changes: 10 additions & 1 deletion query_merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ func (q *MergeQuery) Err(err error) *MergeQuery {
return q
}

// Comment prepends a comment to the beginning of the query.
// This is useful for debugging or identifying queries in database logs.
func (q *MergeQuery) Comment(c string) *MergeQuery {
q.setComment(c)
return q
}

// Apply calls the fn passing the MergeQuery as an argument.
func (q *MergeQuery) Apply(fn func(*MergeQuery) *MergeQuery) *MergeQuery {
if fn != nil {
Expand Down Expand Up @@ -231,8 +238,10 @@ func (q *MergeQuery) scanOrExec(
return nil, err
}

q.setComment(commentFromContext(ctx))

// Generate the query before checking hasReturning.
queryBytes, err := q.AppendQuery(q.db.fmter, q.db.makeQueryBytes())
queryBytes, err := q.AppendQuery(q.db.fmter, q.appendComment(q.db.makeQueryBytes()))
if err != nil {
return nil, err
}
Expand Down
38 changes: 32 additions & 6 deletions query_select.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ func (q *SelectQuery) Err(err error) *SelectQuery {
return q
}

// Comment prepends a comment to the beginning of the query.
// This is useful for debugging or identifying queries in database logs.
func (q *SelectQuery) Comment(c string) *SelectQuery {
q.setComment(c)
return q
}

// Apply calls the fn passing the SelectQuery as an argument.
func (q *SelectQuery) Apply(fn func(*SelectQuery) *SelectQuery) *SelectQuery {
if fn != nil {
Expand Down Expand Up @@ -807,7 +814,9 @@ func (q *SelectQuery) Rows(ctx context.Context) (*sql.Rows, error) {
return nil, err
}

queryBytes, err := q.AppendQuery(q.db.fmter, q.db.makeQueryBytes())
q.setComment(commentFromContext(ctx))

queryBytes, err := q.AppendQuery(q.db.fmter, q.appendComment(q.db.makeQueryBytes()))
if err != nil {
return nil, err
}
Expand All @@ -828,7 +837,9 @@ func (q *SelectQuery) Exec(ctx context.Context, dest ...interface{}) (res sql.Re
return nil, err
}

queryBytes, err := q.AppendQuery(q.db.fmter, q.db.makeQueryBytes())
q.setComment(commentFromContext(ctx))

queryBytes, err := q.AppendQuery(q.db.fmter, q.appendComment(q.db.makeQueryBytes()))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -875,7 +886,9 @@ func (q *SelectQuery) Scan(ctx context.Context, dest ...interface{}) error {
return err
}

queryBytes, err := q.AppendQuery(q.db.fmter, q.db.makeQueryBytes())
q.setComment(commentFromContext(ctx))

queryBytes, err := q.AppendQuery(q.db.fmter, q.appendComment(q.db.makeQueryBytes()))
if err != nil {
return err
}
Expand Down Expand Up @@ -929,7 +942,9 @@ func (q *SelectQuery) Count(ctx context.Context) (int, error) {

qq := countQuery{q}

queryBytes, err := qq.AppendQuery(q.db.fmter, nil)
q.setComment(commentFromContext(ctx))

queryBytes, err := qq.AppendQuery(q.db.fmter, q.appendComment(nil))
if err != nil {
return 0, err
}
Expand Down Expand Up @@ -1021,7 +1036,9 @@ func (q *SelectQuery) Exists(ctx context.Context) (bool, error) {
func (q *SelectQuery) selectExists(ctx context.Context) (bool, error) {
qq := selectExistsQuery{q}

queryBytes, err := qq.AppendQuery(q.db.fmter, nil)
q.setComment(commentFromContext(ctx))

queryBytes, err := qq.AppendQuery(q.db.fmter, q.appendComment(nil))
if err != nil {
return false, err
}
Expand All @@ -1040,7 +1057,9 @@ func (q *SelectQuery) selectExists(ctx context.Context) (bool, error) {
func (q *SelectQuery) whereExists(ctx context.Context) (bool, error) {
qq := whereExistsQuery{q}

queryBytes, err := qq.AppendQuery(q.db.fmter, nil)
q.setComment(commentFromContext(ctx))

queryBytes, err := qq.AppendQuery(q.db.fmter, q.appendComment(nil))
if err != nil {
return false, err
}
Expand Down Expand Up @@ -1082,6 +1101,13 @@ type selectQueryBuilder struct {
*SelectQuery
}

// Comment prepends a comment to the beginning of the query.
// This is useful for debugging or identifying queries in database logs.
func (q *selectQueryBuilder) Comment(c string) QueryBuilder {
q.setComment(c)
return q
}

func (q *selectQueryBuilder) WhereGroup(
sep string, fn func(QueryBuilder) QueryBuilder,
) QueryBuilder {
Expand Down
18 changes: 17 additions & 1 deletion query_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ func (q *UpdateQuery) Err(err error) *UpdateQuery {
return q
}

// Comment prepends a comment to the beginning of the query.
// This is useful for debugging or identifying queries in database logs.
func (q *UpdateQuery) Comment(c string) *UpdateQuery {
q.setComment(c)
return q
}

// Apply calls the fn passing the SelectQuery as an argument.
func (q *UpdateQuery) Apply(fn func(*UpdateQuery) *UpdateQuery) *UpdateQuery {
if fn != nil {
Expand Down Expand Up @@ -505,8 +512,10 @@ func (q *UpdateQuery) scanOrExec(
return nil, err
}

q.setComment(commentFromContext(ctx))

// Generate the query before checking hasReturning.
queryBytes, err := q.AppendQuery(q.db.fmter, q.db.makeQueryBytes())
queryBytes, err := q.AppendQuery(q.db.fmter, q.appendComment(q.db.makeQueryBytes()))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -604,6 +613,13 @@ type updateQueryBuilder struct {
*UpdateQuery
}

// Comment prepends a comment to the beginning of the query.
// This is useful for debugging or identifying queries in database logs.
func (q *updateQueryBuilder) Comment(c string) QueryBuilder {
q.setComment(c)
return q
}

func (q *updateQueryBuilder) WhereGroup(
sep string, fn func(QueryBuilder) QueryBuilder,
) QueryBuilder {
Expand Down