diff --git a/go.mod b/go.mod index e2846c206..2a6658319 100644 --- a/go.mod +++ b/go.mod @@ -47,10 +47,10 @@ require ( github.com/superseriousbusiness/oauth2/v4 v4.3.2-SSB.0.20230227143000-f4900831d6c8 github.com/tdewolff/minify/v2 v2.12.9 github.com/ulule/limiter/v3 v3.11.2 - github.com/uptrace/bun v1.1.14 - github.com/uptrace/bun/dialect/pgdialect v1.1.14 - github.com/uptrace/bun/dialect/sqlitedialect v1.1.14 - github.com/uptrace/bun/extra/bunotel v1.1.14 + github.com/uptrace/bun v1.1.15 + github.com/uptrace/bun/dialect/pgdialect v1.1.15 + github.com/uptrace/bun/dialect/sqlitedialect v1.1.15 + github.com/uptrace/bun/extra/bunotel v1.1.15 github.com/wagslane/go-password-validator v0.3.0 github.com/yuin/goldmark v1.5.6 go.opentelemetry.io/otel v1.17.0 @@ -156,7 +156,7 @@ require ( github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.11 // indirect - github.com/uptrace/opentelemetry-go-extra/otelsql v0.2.1 // indirect + github.com/uptrace/opentelemetry-go-extra/otelsql v0.2.2 // indirect github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.17.0 // indirect diff --git a/go.sum b/go.sum index e12514d22..0da102d44 100644 --- a/go.sum +++ b/go.sum @@ -576,16 +576,16 @@ github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4d github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= github.com/ulule/limiter/v3 v3.11.2 h1:P4yOrxoEMJbOTfRJR2OzjL90oflzYPPmWg+dvwN2tHA= github.com/ulule/limiter/v3 v3.11.2/go.mod h1:QG5GnFOCV+k7lrL5Y8kgEeeflPH3+Cviqlqa8SVSQxI= -github.com/uptrace/bun v1.1.14 h1:S5vvNnjEynJ0CvnrBOD7MIRW7q/WbtvFXrdfy0lddAM= -github.com/uptrace/bun v1.1.14/go.mod h1:RHk6DrIisO62dv10pUOJCz5MphXThuOTpVNYEYv7NI8= -github.com/uptrace/bun/dialect/pgdialect v1.1.14 h1:b7+V1KDJPQSFYgkG/6YLXCl2uvwEY3kf/GSM7hTHRDY= -github.com/uptrace/bun/dialect/pgdialect v1.1.14/go.mod h1:v6YiaXmnKQ2FlhRD2c0ZfKd+QXH09pYn4H8ojaavkKk= -github.com/uptrace/bun/dialect/sqlitedialect v1.1.14 h1:SlwXLxr+N1kEo8Q0cheRlnIZLZlWniEB1OI+jkiLgWE= -github.com/uptrace/bun/dialect/sqlitedialect v1.1.14/go.mod h1:9RTEj1l4bB9a4l1Mnc9y4COTwWlFYe1dh6fyxq1rR7A= -github.com/uptrace/bun/extra/bunotel v1.1.14 h1:jKA1zNfD2/Y/O3eFP15ao+V0cMigXN+ReNbsVUqrOhg= -github.com/uptrace/bun/extra/bunotel v1.1.14/go.mod h1:BBuePZ4ciMqoeyRfef4GL7Z75FsiOm3Q3fvNt0z4sQk= -github.com/uptrace/opentelemetry-go-extra/otelsql v0.2.1 h1:sCYkntVVoSMuQuyRBaEkedb1qS1KeJJaqKbdtNfTsfM= -github.com/uptrace/opentelemetry-go-extra/otelsql v0.2.1/go.mod h1:1frv9RN1rlTq0jzCq+mVuEQisubZCQ4OU6S/8CaHzGY= +github.com/uptrace/bun v1.1.15 h1:uxLNIo1VN8pkJ8rykwPBd9qYg4NDTvjHIintnwoQ3QY= +github.com/uptrace/bun v1.1.15/go.mod h1:7HnsMRRvpLFUcquJxp22JO8PsWKpFQO/gNXqqsuGWg8= +github.com/uptrace/bun/dialect/pgdialect v1.1.15 h1:fLmWvUPNqOhnZxJ4IqypXOQGxmXQJr1ISaIscRddPPY= +github.com/uptrace/bun/dialect/pgdialect v1.1.15/go.mod h1:777qGnrISxHQ+Ulj5YbmmwywfQLLmIYJIoCbGZ+M7lY= +github.com/uptrace/bun/dialect/sqlitedialect v1.1.15 h1:uZqBNm4iJnDO4mZ1UXUzGqMhjxB5SAsafMF58s2gmkQ= +github.com/uptrace/bun/dialect/sqlitedialect v1.1.15/go.mod h1:ymLR6ladQrWS7eYTX45+lTIK7vocXiE3jXNBxUZMJlU= +github.com/uptrace/bun/extra/bunotel v1.1.15 h1:ulzA0UqqMmTXsu7M0F23VGIdY1gFyLxgZhlAZwPMHXE= +github.com/uptrace/bun/extra/bunotel v1.1.15/go.mod h1:nOsIf8xAROpI5ZbiO9Ys/fE2wJB23wMBBrH8XsVhEJk= +github.com/uptrace/opentelemetry-go-extra/otelsql v0.2.2 h1:USRngIQppxeyb39XzkVHXwQesKK0+JSwnHE/1c7fgic= +github.com/uptrace/opentelemetry-go-extra/otelsql v0.2.2/go.mod h1:1frv9RN1rlTq0jzCq+mVuEQisubZCQ4OU6S/8CaHzGY= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasthttp v1.14.0/go.mod h1:ol1PCaL0dX20wC0htZ7sYCsvCYmrouYra0zHzaclZhE= diff --git a/vendor/github.com/uptrace/bun/CHANGELOG.md b/vendor/github.com/uptrace/bun/CHANGELOG.md index 6280b3165..f1d9577c3 100644 --- a/vendor/github.com/uptrace/bun/CHANGELOG.md +++ b/vendor/github.com/uptrace/bun/CHANGELOG.md @@ -1,3 +1,23 @@ +## [1.1.15](https://github.com/uptrace/bun/compare/v1.1.14...v1.1.15) (2023-09-10) + + +### Bug Fixes + +* "model does not have column" error ([#850](https://github.com/uptrace/bun/issues/850)) ([16367aa](https://github.com/uptrace/bun/commit/16367aabb34b98766d28e0678f9d47710f451fae)) +* alloc when mounting ([#891](https://github.com/uptrace/bun/issues/891)) ([f2256f1](https://github.com/uptrace/bun/commit/f2256f10a1d328fb924ca79cde76e77641398573)) +* index hints have to be specified following a table name ([4a2ae85](https://github.com/uptrace/bun/commit/4a2ae853a1509bb300bc2d96471505caee799e43)) +* make Rows.Close to drain messages ([5ceba07](https://github.com/uptrace/bun/commit/5ceba076668eb7aaddb1d8a56202256d5e6c1ead)) +* run hooks on Rows ([#892](https://github.com/uptrace/bun/issues/892)) ([f652b3d](https://github.com/uptrace/bun/commit/f652b3d399a3dc46c856eb8c0f10140a12ea4310)) +* scan error [#709](https://github.com/uptrace/bun/issues/709) ([#837](https://github.com/uptrace/bun/issues/837)) ([b82afa5](https://github.com/uptrace/bun/commit/b82afa52633b2a1b352db6de4ff0d369d5468a07)) + + +### Features + +* add bun.NullZero ([786bb6b](https://github.com/uptrace/bun/commit/786bb6bfeba3c12f8b28579d61e4794d9fb3e373)) +* **bunotel:** add options for set otel providers ([#836](https://github.com/uptrace/bun/issues/836)) ([806e632](https://github.com/uptrace/bun/commit/806e6323f60b4703b03a71c113c263d0afc95b35)) + + + ## [1.1.14](https://github.com/uptrace/bun/compare/v1.1.13...v1.1.14) (2023-05-24) diff --git a/vendor/github.com/uptrace/bun/bun.go b/vendor/github.com/uptrace/bun/bun.go index 923be3116..9cb1f1ffe 100644 --- a/vendor/github.com/uptrace/bun/bun.go +++ b/vendor/github.com/uptrace/bun/bun.go @@ -10,6 +10,7 @@ type ( Safe = schema.Safe Ident = schema.Ident + Name = schema.Name NullTime = schema.NullTime BaseModel = schema.BaseModel @@ -82,3 +83,7 @@ func SetLogger(logger internal.Logging) { func In(slice interface{}) schema.QueryAppender { return schema.In(slice) } + +func NullZero(value interface{}) schema.QueryAppender { + return schema.NullZero(value) +} diff --git a/vendor/github.com/uptrace/bun/dialect/append.go b/vendor/github.com/uptrace/bun/dialect/append.go index 0a25ee22d..48f092284 100644 --- a/vendor/github.com/uptrace/bun/dialect/append.go +++ b/vendor/github.com/uptrace/bun/dialect/append.go @@ -48,14 +48,31 @@ func appendFloat(b []byte, v float64, bitSize int) []byte { //------------------------------------------------------------------------------ -func AppendIdent(b []byte, field string, quote byte) []byte { - return appendIdent(b, internal.Bytes(field), quote) +func AppendName(b []byte, ident string, quote byte) []byte { + return appendName(b, internal.Bytes(ident), quote) } -func appendIdent(b, src []byte, quote byte) []byte { +func appendName(b, ident []byte, quote byte) []byte { + b = append(b, quote) + for _, c := range ident { + if c == quote { + b = append(b, quote, quote) + } else { + b = append(b, c) + } + } + b = append(b, quote) + return b +} + +func AppendIdent(b []byte, name string, quote byte) []byte { + return appendIdent(b, internal.Bytes(name), quote) +} + +func appendIdent(b, name []byte, quote byte) []byte { var quoted bool loop: - for _, c := range src { + for _, c := range name { switch c { case '*': if !quoted { diff --git a/vendor/github.com/uptrace/bun/dialect/pgdialect/version.go b/vendor/github.com/uptrace/bun/dialect/pgdialect/version.go index 2f7abbf6a..bea5c4d2d 100644 --- a/vendor/github.com/uptrace/bun/dialect/pgdialect/version.go +++ b/vendor/github.com/uptrace/bun/dialect/pgdialect/version.go @@ -2,5 +2,5 @@ // Version is the current release version. func Version() string { - return "1.1.14" + return "1.1.15" } diff --git a/vendor/github.com/uptrace/bun/dialect/sqlitedialect/version.go b/vendor/github.com/uptrace/bun/dialect/sqlitedialect/version.go index af7cebc89..4fbb58cee 100644 --- a/vendor/github.com/uptrace/bun/dialect/sqlitedialect/version.go +++ b/vendor/github.com/uptrace/bun/dialect/sqlitedialect/version.go @@ -2,5 +2,5 @@ // Version is the current release version. func Version() string { - return "1.1.14" + return "1.1.15" } diff --git a/vendor/github.com/uptrace/bun/extra/bunotel/option.go b/vendor/github.com/uptrace/bun/extra/bunotel/option.go index dc294ffa5..4c9c90a30 100644 --- a/vendor/github.com/uptrace/bun/extra/bunotel/option.go +++ b/vendor/github.com/uptrace/bun/extra/bunotel/option.go @@ -2,7 +2,9 @@ import ( "go.opentelemetry.io/otel/attribute" + "go.opentelemetry.io/otel/metric" semconv "go.opentelemetry.io/otel/semconv/v1.12.0" + "go.opentelemetry.io/otel/trace" ) type Option func(h *QueryHook) @@ -30,3 +32,23 @@ func WithFormattedQueries(format bool) Option { h.formatQueries = format } } + +// WithTracerProvider returns an Option to use the TracerProvider when +// creating a Tracer. +func WithTracerProvider(tp trace.TracerProvider) Option { + return func(h *QueryHook) { + if tp != nil { + h.tracer = tp.Tracer("github.com/uptrace/bun") + } + } +} + +// WithMeterProvider returns an Option to use the MeterProvider when +// creating a Meter. +func WithMeterProvider(mp metric.MeterProvider) Option { + return func(h *QueryHook) { + if mp != nil { + h.meter = mp.Meter("github.com/uptrace/bun") + } + } +} diff --git a/vendor/github.com/uptrace/bun/extra/bunotel/otel.go b/vendor/github.com/uptrace/bun/extra/bunotel/otel.go index b9737b0bc..d0672e7c2 100644 --- a/vendor/github.com/uptrace/bun/extra/bunotel/otel.go +++ b/vendor/github.com/uptrace/bun/extra/bunotel/otel.go @@ -20,20 +20,12 @@ "github.com/uptrace/opentelemetry-go-extra/otelsql" ) -var ( - tracer = otel.Tracer("github.com/uptrace/bun") - meter = otel.Meter("github.com/uptrace/bun") - - queryHistogram, _ = meter.Int64Histogram( - "go.sql.query_timing", - metric.WithDescription("Timing of processed queries"), - metric.WithUnit("milliseconds"), - ) -) - type QueryHook struct { - attrs []attribute.KeyValue - formatQueries bool + attrs []attribute.KeyValue + formatQueries bool + tracer trace.Tracer + meter metric.Meter + queryHistogram metric.Int64Histogram } var _ bun.QueryHook = (*QueryHook)(nil) @@ -43,6 +35,17 @@ func NewQueryHook(opts ...Option) *QueryHook { for _, opt := range opts { opt(h) } + if h.tracer == nil { + h.tracer = otel.Tracer("github.com/uptrace/bun") + } + if h.meter == nil { + h.meter = otel.Meter("github.com/uptrace/bun") + } + h.queryHistogram, _ = h.meter.Int64Histogram( + "go.sql.query_timing", + metric.WithDescription("Timing of processed queries"), + metric.WithUnit("milliseconds"), + ) return h } @@ -57,7 +60,7 @@ func (h *QueryHook) Init(db *bun.DB) { } func (h *QueryHook) BeforeQuery(ctx context.Context, event *bun.QueryEvent) context.Context { - ctx, _ = tracer.Start(ctx, "", trace.WithSpanKind(trace.SpanKindClient)) + ctx, _ = h.tracer.Start(ctx, "", trace.WithSpanKind(trace.SpanKindClient)) return ctx } @@ -75,7 +78,7 @@ func (h *QueryHook) AfterQuery(ctx context.Context, event *bun.QueryEvent) { } dur := time.Since(event.StartTime) - queryHistogram.Record(ctx, dur.Milliseconds(), metric.WithAttributes(labels...)) + h.queryHistogram.Record(ctx, dur.Milliseconds(), metric.WithAttributes(labels...)) span := trace.SpanFromContext(ctx) if !span.IsRecording() { diff --git a/vendor/github.com/uptrace/bun/internal/util.go b/vendor/github.com/uptrace/bun/internal/util.go index 641309725..66b92b3c5 100644 --- a/vendor/github.com/uptrace/bun/internal/util.go +++ b/vendor/github.com/uptrace/bun/internal/util.go @@ -55,3 +55,27 @@ func Unwrap(err error) error { } return u.Unwrap() } + +func FieldByIndexAlloc(v reflect.Value, index []int) reflect.Value { + if len(index) == 1 { + return v.Field(index[0]) + } + + for i, idx := range index { + if i > 0 { + v = indirectNil(v) + } + v = v.Field(idx) + } + return v +} + +func indirectNil(v reflect.Value) reflect.Value { + if v.Kind() == reflect.Ptr { + if v.IsNil() { + v.Set(reflect.New(v.Type().Elem())) + } + v = v.Elem() + } + return v +} diff --git a/vendor/github.com/uptrace/bun/model_table_struct.go b/vendor/github.com/uptrace/bun/model_table_struct.go index fadc9284c..65e076d23 100644 --- a/vendor/github.com/uptrace/bun/model_table_struct.go +++ b/vendor/github.com/uptrace/bun/model_table_struct.go @@ -8,6 +8,7 @@ "strings" "time" + "github.com/uptrace/bun/internal" "github.com/uptrace/bun/schema" ) @@ -234,7 +235,7 @@ func (m *structTableModel) parentIndex() []int { } func (m *structTableModel) mount(host reflect.Value) { - m.strct = host.FieldByIndex(m.rel.Field.Index) + m.strct = internal.FieldByIndexAlloc(host, m.rel.Field.Index) m.structInited = false } diff --git a/vendor/github.com/uptrace/bun/package.json b/vendor/github.com/uptrace/bun/package.json index 8398427c6..b4c8d6ca6 100644 --- a/vendor/github.com/uptrace/bun/package.json +++ b/vendor/github.com/uptrace/bun/package.json @@ -1,6 +1,6 @@ { "name": "gobun", - "version": "1.1.14", + "version": "1.1.15", "main": "index.js", "repository": "git@github.com:uptrace/bun.git", "author": "Vladimir Mihailenco ", diff --git a/vendor/github.com/uptrace/bun/query_base.go b/vendor/github.com/uptrace/bun/query_base.go index 4b3545d0d..7c7bf681a 100644 --- a/vendor/github.com/uptrace/bun/query_base.go +++ b/vendor/github.com/uptrace/bun/query_base.go @@ -588,7 +588,7 @@ func (q *baseQuery) exec( ) (sql.Result, error) { ctx, event := q.db.beforeQuery(ctx, iquery, query, nil, query, q.model) res, err := q.conn.ExecContext(ctx, query) - q.db.afterQuery(ctx, event, nil, err) + q.db.afterQuery(ctx, event, res, err) return res, err } diff --git a/vendor/github.com/uptrace/bun/query_select.go b/vendor/github.com/uptrace/bun/query_select.go index a24a9f6f1..c0e145110 100644 --- a/vendor/github.com/uptrace/bun/query_select.go +++ b/vendor/github.com/uptrace/bun/query_select.go @@ -551,6 +551,11 @@ func (q *SelectQuery) appendQuery( } } + b, err = q.appendIndexHints(fmter, b) + if err != nil { + return nil, err + } + if err := q.forEachInlineRelJoin(func(j *relationJoin) error { b = append(b, ' ') b, err = j.appendHasOneJoin(fmter, b, q) @@ -566,11 +571,6 @@ func (q *SelectQuery) appendQuery( } } - b, err = q.appendIndexHints(fmter, b) - if err != nil { - return nil, err - } - b, err = q.appendWhere(fmter, b, true) if err != nil { return nil, err @@ -813,7 +813,11 @@ func (q *SelectQuery) Rows(ctx context.Context) (*sql.Rows, error) { } query := internal.String(queryBytes) - return q.conn.QueryContext(ctx, query) + + ctx, event := q.db.beforeQuery(ctx, q, query, nil, query, q.model) + rows, err := q.conn.QueryContext(ctx, query) + q.db.afterQuery(ctx, event, nil, err) + return rows, err } func (q *SelectQuery) Exec(ctx context.Context, dest ...interface{}) (res sql.Result, err error) { diff --git a/vendor/github.com/uptrace/bun/query_update.go b/vendor/github.com/uptrace/bun/query_update.go index 708bcfbce..146d695b8 100644 --- a/vendor/github.com/uptrace/bun/query_update.go +++ b/vendor/github.com/uptrace/bun/query_update.go @@ -271,10 +271,18 @@ func (q *UpdateQuery) mustAppendSet(fmter schema.Formatter, b []byte) (_ []byte, switch model := q.tableModel.(type) { case *structTableModel: + pos := len(b) b, err = q.appendSetStruct(fmter, b, model) if err != nil { return nil, err } + + // Validate if no values were appended after SET clause. + // e.g. UPDATE users SET WHERE id = 1 + // See issues858 + if len(b) == pos { + return nil, errors.New("bun: empty SET clause is not allowed in the UPDATE query") + } case *sliceTableModel: return nil, errors.New("bun: to bulk Update, use CTE and VALUES") default: diff --git a/vendor/github.com/uptrace/bun/relation_join.go b/vendor/github.com/uptrace/bun/relation_join.go index 200f6758a..87503fbeb 100644 --- a/vendor/github.com/uptrace/bun/relation_join.go +++ b/vendor/github.com/uptrace/bun/relation_join.go @@ -178,7 +178,12 @@ func (j *relationJoin) m2mQuery(q *SelectQuery) *SelectQuery { baseTable := j.BaseModel.Table() if j.Relation.M2MTable != nil { - q = q.ColumnExpr(string(j.Relation.M2MTable.SQLAlias) + ".*") + fields := append(j.Relation.M2MBaseFields, j.Relation.M2MJoinFields...) + + b := make([]byte, 0, len(fields)) + b = appendColumns(b, j.Relation.M2MTable.SQLAlias, fields) + + q = q.ColumnExpr(internal.String(b)) } //nolint diff --git a/vendor/github.com/uptrace/bun/schema/append.go b/vendor/github.com/uptrace/bun/schema/append.go index 6f633b101..0cfc1180b 100644 --- a/vendor/github.com/uptrace/bun/schema/append.go +++ b/vendor/github.com/uptrace/bun/schema/append.go @@ -81,7 +81,7 @@ func appendIn(fmter Formatter, b []byte, slice reflect.Value) []byte { sliceLen := slice.Len() if sliceLen == 0 { - return append(b, "NULL"...) + return dialect.AppendNull(b) } for i := 0; i < sliceLen; i++ { @@ -104,3 +104,22 @@ func appendIn(fmter Formatter, b []byte, slice reflect.Value) []byte { } return b } + +//------------------------------------------------------------------------------ + +func NullZero(value interface{}) QueryAppender { + return nullZero{ + value: value, + } +} + +type nullZero struct { + value interface{} +} + +func (nz nullZero) AppendQuery(fmter Formatter, b []byte) (_ []byte, err error) { + if isZero(nz.value) { + return dialect.AppendNull(b), nil + } + return fmter.AppendValue(b, reflect.ValueOf(nz.value)), nil +} diff --git a/vendor/github.com/uptrace/bun/schema/field.go b/vendor/github.com/uptrace/bun/schema/field.go index 283a3b992..a3b086054 100644 --- a/vendor/github.com/uptrace/bun/schema/field.go +++ b/vendor/github.com/uptrace/bun/schema/field.go @@ -5,6 +5,7 @@ "reflect" "github.com/uptrace/bun/dialect" + "github.com/uptrace/bun/internal" "github.com/uptrace/bun/internal/tagparser" ) @@ -50,7 +51,7 @@ func (f *Field) Clone() *Field { } func (f *Field) Value(strct reflect.Value) reflect.Value { - return fieldByIndexAlloc(strct, f.Index) + return internal.FieldByIndexAlloc(strct, f.Index) } func (f *Field) HasNilValue(v reflect.Value) bool { @@ -117,7 +118,7 @@ func (f *Field) ScanValue(strct reflect.Value, src interface{}) error { return nil } - fv := fieldByIndexAlloc(strct, f.Index) + fv := internal.FieldByIndexAlloc(strct, f.Index) return f.ScanWithCheck(fv, src) } diff --git a/vendor/github.com/uptrace/bun/schema/formatter.go b/vendor/github.com/uptrace/bun/schema/formatter.go index 1fba1b59e..1d8d9a9ee 100644 --- a/vendor/github.com/uptrace/bun/schema/formatter.go +++ b/vendor/github.com/uptrace/bun/schema/formatter.go @@ -42,6 +42,10 @@ func (f Formatter) IdentQuote() byte { return f.dialect.IdentQuote() } +func (f Formatter) AppendName(b []byte, name string) []byte { + return dialect.AppendName(b, name, f.IdentQuote()) +} + func (f Formatter) AppendIdent(b []byte, ident string) []byte { return dialect.AppendIdent(b, ident, f.IdentQuote()) } diff --git a/vendor/github.com/uptrace/bun/schema/reflect.go b/vendor/github.com/uptrace/bun/schema/reflect.go index f13826a6c..89be8eeb6 100644 --- a/vendor/github.com/uptrace/bun/schema/reflect.go +++ b/vendor/github.com/uptrace/bun/schema/reflect.go @@ -46,27 +46,3 @@ func fieldByIndex(v reflect.Value, index []int) (_ reflect.Value, ok bool) { } return v, true } - -func fieldByIndexAlloc(v reflect.Value, index []int) reflect.Value { - if len(index) == 1 { - return v.Field(index[0]) - } - - for i, idx := range index { - if i > 0 { - v = indirectNil(v) - } - v = v.Field(idx) - } - return v -} - -func indirectNil(v reflect.Value) reflect.Value { - if v.Kind() == reflect.Ptr { - if v.IsNil() { - v.Set(reflect.New(v.Type().Elem())) - } - v = v.Elem() - } - return v -} diff --git a/vendor/github.com/uptrace/bun/schema/sqlfmt.go b/vendor/github.com/uptrace/bun/schema/sqlfmt.go index a4ed24af6..7b4a9493f 100644 --- a/vendor/github.com/uptrace/bun/schema/sqlfmt.go +++ b/vendor/github.com/uptrace/bun/schema/sqlfmt.go @@ -27,7 +27,19 @@ func (s Safe) AppendQuery(fmter Formatter, b []byte) ([]byte, error) { //------------------------------------------------------------------------------ -// Ident represents a SQL identifier, for example, table or column name. +// Name represents a single SQL name, for example, a column name. +type Name string + +var _ QueryAppender = (*Name)(nil) + +func (s Name) AppendQuery(fmter Formatter, b []byte) ([]byte, error) { + return fmter.AppendName(b, string(s)), nil +} + +//------------------------------------------------------------------------------ + +// Ident represents a SQL identifier, for example, +// a fully qualified column name such as `table_name.col_name`. type Ident string var _ QueryAppender = (*Ident)(nil) diff --git a/vendor/github.com/uptrace/bun/schema/table.go b/vendor/github.com/uptrace/bun/schema/table.go index 9eb7d1bfe..cd0ff20b2 100644 --- a/vendor/github.com/uptrace/bun/schema/table.go +++ b/vendor/github.com/uptrace/bun/schema/table.go @@ -4,6 +4,7 @@ "database/sql" "fmt" "reflect" + "strconv" "strings" "sync" "time" @@ -806,18 +807,38 @@ func (t *Table) m2mRelation(field *Field) *Relation { return rel } -func (t *Table) inlineFields(field *Field, seen map[reflect.Type]struct{}) { - if seen == nil { - seen = map[reflect.Type]struct{}{t.Type: {}} - } +type seenKey struct { + Table reflect.Type + FieldIndex string +} - if _, ok := seen[field.IndirectType]; ok { - return +type seenMap map[seenKey]struct{} + +func NewSeenKey(table reflect.Type, fieldIndex []int) (key seenKey) { + key.Table = table + for _, index := range fieldIndex { + key.FieldIndex += strconv.Itoa(index) + "-" + } + return key +} + +func (s seenMap) Clone() seenMap { + t := make(seenMap) + for k, v := range s { + t[k] = v + } + return t +} + +func (t *Table) inlineFields(field *Field, seen seenMap) { + if seen == nil { + seen = make(seenMap) } - seen[field.IndirectType] = struct{}{} joinTable := t.dialect.Tables().Ref(field.IndirectType) for _, f := range joinTable.allFields { + key := NewSeenKey(joinTable.Type, f.Index) + f = f.Clone() f.GoName = field.GoName + "_" + f.GoName f.Name = field.Name + "__" + f.Name @@ -834,7 +855,9 @@ func (t *Table) inlineFields(field *Field, seen map[reflect.Type]struct{}) { continue } - if _, ok := seen[f.IndirectType]; !ok { + if _, ok := seen[key]; !ok { + seen = seen.Clone() + seen[key] = struct{}{} t.inlineFields(f, seen) } } diff --git a/vendor/github.com/uptrace/bun/schema/zerochecker.go b/vendor/github.com/uptrace/bun/schema/zerochecker.go index f088b8c2c..f24e51d30 100644 --- a/vendor/github.com/uptrace/bun/schema/zerochecker.go +++ b/vendor/github.com/uptrace/bun/schema/zerochecker.go @@ -11,6 +11,45 @@ type isZeroer interface { IsZero() bool } +func isZero(v interface{}) bool { + switch v := v.(type) { + case isZeroer: + return v.IsZero() + case string: + return v == "" + case []byte: + return v == nil + case int: + return v == 0 + case int64: + return v == 0 + case uint: + return v == 0 + case uint64: + return v == 0 + case float32: + return v == 0 + case float64: + return v == 0 + case int8: + return v == 0 + case int16: + return v == 0 + case int32: + return v == 0 + case uint8: + return v == 0 + case uint16: + return v == 0 + case uint32: + return v == 0 + default: + rv := reflect.ValueOf(v) + fn := zeroChecker(rv.Type()) + return fn(rv) + } +} + type IsZeroerFunc func(reflect.Value) bool func zeroChecker(typ reflect.Type) IsZeroerFunc { diff --git a/vendor/github.com/uptrace/bun/version.go b/vendor/github.com/uptrace/bun/version.go index a92db5c7b..371014de7 100644 --- a/vendor/github.com/uptrace/bun/version.go +++ b/vendor/github.com/uptrace/bun/version.go @@ -2,5 +2,5 @@ // Version is the current release version. func Version() string { - return "1.1.14" + return "1.1.15" } diff --git a/vendor/github.com/uptrace/opentelemetry-go-extra/otelsql/README.md b/vendor/github.com/uptrace/opentelemetry-go-extra/otelsql/README.md index dbded166d..64324c17f 100644 --- a/vendor/github.com/uptrace/opentelemetry-go-extra/otelsql/README.md +++ b/vendor/github.com/uptrace/opentelemetry-go-extra/otelsql/README.md @@ -2,7 +2,7 @@ # database/sql instrumentation for OpenTelemetry Go -[database/sql OpenTelemetry instrumentation](https://uptrace.dev/opentelemetry/instrumentations/go-database-sql.html) +[database/sql OpenTelemetry instrumentation](https://uptrace.dev/getinstrument/opentelemetry-database-sql.html) records database queries (including `Tx` and `Stmt` queries) and reports `DBStats` metrics. ## Installation diff --git a/vendor/github.com/uptrace/opentelemetry-go-extra/otelsql/version.go b/vendor/github.com/uptrace/opentelemetry-go-extra/otelsql/version.go index 95cd98269..955109b16 100644 --- a/vendor/github.com/uptrace/opentelemetry-go-extra/otelsql/version.go +++ b/vendor/github.com/uptrace/opentelemetry-go-extra/otelsql/version.go @@ -2,5 +2,5 @@ // Version is the current release version. func Version() string { - return "0.2.1" + return "0.2.2" } diff --git a/vendor/modules.txt b/vendor/modules.txt index c9dbd7b96..dae43a87f 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -699,7 +699,7 @@ github.com/ugorji/go/codec github.com/ulule/limiter/v3 github.com/ulule/limiter/v3/drivers/store/common github.com/ulule/limiter/v3/drivers/store/memory -# github.com/uptrace/bun v1.1.14 +# github.com/uptrace/bun v1.1.15 ## explicit; go 1.19 github.com/uptrace/bun github.com/uptrace/bun/dialect @@ -711,16 +711,16 @@ github.com/uptrace/bun/internal/parser github.com/uptrace/bun/internal/tagparser github.com/uptrace/bun/migrate github.com/uptrace/bun/schema -# github.com/uptrace/bun/dialect/pgdialect v1.1.14 +# github.com/uptrace/bun/dialect/pgdialect v1.1.15 ## explicit; go 1.19 github.com/uptrace/bun/dialect/pgdialect -# github.com/uptrace/bun/dialect/sqlitedialect v1.1.14 +# github.com/uptrace/bun/dialect/sqlitedialect v1.1.15 ## explicit; go 1.19 github.com/uptrace/bun/dialect/sqlitedialect -# github.com/uptrace/bun/extra/bunotel v1.1.14 +# github.com/uptrace/bun/extra/bunotel v1.1.15 ## explicit; go 1.19 github.com/uptrace/bun/extra/bunotel -# github.com/uptrace/opentelemetry-go-extra/otelsql v0.2.1 +# github.com/uptrace/opentelemetry-go-extra/otelsql v0.2.2 ## explicit; go 1.18 github.com/uptrace/opentelemetry-go-extra/otelsql # github.com/vmihailenco/msgpack/v5 v5.3.5