diff --git a/go.mod b/go.mod index 58103299c..dcf67cb6b 100644 --- a/go.mod +++ b/go.mod @@ -28,9 +28,9 @@ require ( github.com/superseriousbusiness/exifremove v0.0.0-20210330092427-6acd27eac203 github.com/superseriousbusiness/oauth2/v4 v4.3.2-SSB github.com/tdewolff/minify/v2 v2.9.21 - github.com/uptrace/bun v1.0.6 - github.com/uptrace/bun/dialect/pgdialect v1.0.5 - github.com/uptrace/bun/dialect/sqlitedialect v1.0.5 + github.com/uptrace/bun v1.0.9-0.20210922104131-34c982b23581 + github.com/uptrace/bun/dialect/pgdialect v1.0.9-0.20210922104131-34c982b23581 + github.com/uptrace/bun/dialect/sqlitedialect v1.0.9-0.20210922104131-34c982b23581 github.com/urfave/cli/v2 v2.3.0 github.com/wagslane/go-password-validator v0.3.0 golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 diff --git a/go.sum b/go.sum index a290aa3df..2a31d86e6 100644 --- a/go.sum +++ b/go.sum @@ -472,10 +472,16 @@ github.com/ugorji/go/codec v1.2.6/go.mod h1:V6TCNZ4PHqoHGFZuSG1W8nrCzzdgA2DozYxW github.com/uptrace/bun v1.0.5/go.mod h1:aL6D9vPw8DXaTQTwGrEPtUderBYXx7ShUmPfnxnqscw= github.com/uptrace/bun v1.0.6 h1:o9eMq5ePGBXtxbK3SIreOCRr+rIBQzvJH+/s98kYcVM= github.com/uptrace/bun v1.0.6/go.mod h1:aL6D9vPw8DXaTQTwGrEPtUderBYXx7ShUmPfnxnqscw= +github.com/uptrace/bun v1.0.9-0.20210922104131-34c982b23581 h1:W8SAI7irrKSZ3t9MzFwehUyEd6f8ajOprqSzCxHFcxo= +github.com/uptrace/bun v1.0.9-0.20210922104131-34c982b23581/go.mod h1:aL6D9vPw8DXaTQTwGrEPtUderBYXx7ShUmPfnxnqscw= github.com/uptrace/bun/dialect/pgdialect v1.0.5 h1:mq694/aMvs7GwuTar9NIlCLQt/2u4xsF0QMP4I24yHA= github.com/uptrace/bun/dialect/pgdialect v1.0.5/go.mod h1:MKWjO0PC20ris2oJ3dd6mI/762x24Cjwh8XmbqUhM8A= +github.com/uptrace/bun/dialect/pgdialect v1.0.9-0.20210922104131-34c982b23581 h1:3r8Td1Y3I51f9LYcC/3EuQT8zKuCh+OWiQQ8FVHK4Pg= +github.com/uptrace/bun/dialect/pgdialect v1.0.9-0.20210922104131-34c982b23581/go.mod h1:HEGRgyS68SiHcKhFa9LXcDN+KEWo1I4VplvunL0Oi4o= github.com/uptrace/bun/dialect/sqlitedialect v1.0.5 h1:6cIj31YVJr4vvA15C2v76soXL+7WtjFdV6WraApc3r0= github.com/uptrace/bun/dialect/sqlitedialect v1.0.5/go.mod h1:NW2Gctc9ooQXGSD4kYSac2aiF49lo8YJ3ZAr93lH2p8= +github.com/uptrace/bun/dialect/sqlitedialect v1.0.9-0.20210922104131-34c982b23581 h1:Yfbbo8EQffFLL7EEBq2yUirSg3b7NID4sgRGdNlIJa0= +github.com/uptrace/bun/dialect/sqlitedialect v1.0.9-0.20210922104131-34c982b23581/go.mod h1:v1rNdAcJdw8AgD4x4OAJFIRFA9+sANoXK7u21H9Wvkg= github.com/urfave/cli/v2 v2.3.0 h1:qph92Y649prgesehzOrQjdWyxFOp/QVM+6imKHad91M= github.com/urfave/cli/v2 v2.3.0/go.mod h1:LJmUH05zAU44vOAcrfzZQKsZbVcdbOG8rtL3/XcUArI= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= diff --git a/vendor/github.com/uptrace/bun/CHANGELOG.md b/vendor/github.com/uptrace/bun/CHANGELOG.md index c7031830c..5a8f19e20 100644 --- a/vendor/github.com/uptrace/bun/CHANGELOG.md +++ b/vendor/github.com/uptrace/bun/CHANGELOG.md @@ -1,3 +1,31 @@ +## [1.0.8](https://github.com/uptrace/bun/compare/v1.0.7...v1.0.8) (2021-09-18) + + +### Bug Fixes + +* don't append soft delete where for insert queries with on conflict clause ([27c477c](https://github.com/uptrace/bun/commit/27c477ce071d4c49c99a2531d638ed9f20e33461)) +* improve bun.NullTime to accept string ([73ad6f5](https://github.com/uptrace/bun/commit/73ad6f5640a0a9b09f8df2bc4ab9cb510021c50c)) +* make allowzero work with auto-detected primary keys ([82ca87c](https://github.com/uptrace/bun/commit/82ca87c7c49797d507b31fdaacf8343716d4feff)) +* support soft deletes on nil model ([0556e3c](https://github.com/uptrace/bun/commit/0556e3c63692a7f4e48659d52b55ffd9cca0202a)) + + + +## [1.0.7](https://github.com/uptrace/bun/compare/v1.0.6...v1.0.7) (2021-09-15) + + +### Bug Fixes + +* don't append zero time as NULL without nullzero tag ([3b8d9cb](https://github.com/uptrace/bun/commit/3b8d9cb4e39eb17f79a618396bbbe0adbc66b07b)) +* **pgdriver:** return PostgreSQL DATE as a string ([40be0e8](https://github.com/uptrace/bun/commit/40be0e8ea85f8932b7a410a6fc2dd3acd2d18ebc)) +* specify table alias for soft delete where ([5fff1dc](https://github.com/uptrace/bun/commit/5fff1dc1dd74fa48623a24fa79e358a544dfac0b)) + + +### Features + +* add SelectQuery.Exists helper ([c3e59c1](https://github.com/uptrace/bun/commit/c3e59c1bc58b43c4b8e33e7d170ad33a08fbc3c7)) + + + ## [1.0.6](https://github.com/uptrace/bun/compare/v1.0.5...v1.0.6) (2021-09-11) diff --git a/vendor/github.com/uptrace/bun/Makefile b/vendor/github.com/uptrace/bun/Makefile index 54744c617..e121c1d8e 100644 --- a/vendor/github.com/uptrace/bun/Makefile +++ b/vendor/github.com/uptrace/bun/Makefile @@ -4,7 +4,8 @@ test: set -e; for dir in $(ALL_GO_MOD_DIRS); do \ echo "go test in $${dir}"; \ (cd "$${dir}" && \ - go test ./... && \ + go test && \ + env GOOS=linux GOARCH=386 go test && \ go vet); \ done diff --git a/vendor/github.com/uptrace/bun/README.md b/vendor/github.com/uptrace/bun/README.md index b5583c904..434cf6124 100644 --- a/vendor/github.com/uptrace/bun/README.md +++ b/vendor/github.com/uptrace/bun/README.md @@ -30,6 +30,9 @@ Main features are: Resources: +- To ask questions, join [Discord](https://discord.gg/rWtp5Aj) or use + [Discussions](https://github.com/uptrace/bun/discussions). +- [Newsletter](https://blog.uptrace.dev/newsletter/) to get latest updates. - [Examples](https://github.com/uptrace/bun/tree/master/example) - [Documentation](https://bun.uptrace.dev/) - [Reference](https://pkg.go.dev/github.com/uptrace/bun) diff --git a/vendor/github.com/uptrace/bun/db.go b/vendor/github.com/uptrace/bun/db.go index 8514ca93f..9c9c8f9ff 100644 --- a/vendor/github.com/uptrace/bun/db.go +++ b/vendor/github.com/uptrace/bun/db.go @@ -18,8 +18,8 @@ const ( ) type DBStats struct { - Queries uint64 - Errors uint64 + Queries uint32 + Errors uint32 } type DBOption func(db *DB) @@ -70,8 +70,8 @@ func (db *DB) String() string { func (db *DB) DBStats() DBStats { return DBStats{ - Queries: atomic.LoadUint64(&db.stats.Queries), - Errors: atomic.LoadUint64(&db.stats.Errors), + Queries: atomic.LoadUint32(&db.stats.Queries), + Errors: atomic.LoadUint32(&db.stats.Errors), } } diff --git a/vendor/github.com/uptrace/bun/dialect/append.go b/vendor/github.com/uptrace/bun/dialect/append.go index 7040c5155..01e80745a 100644 --- a/vendor/github.com/uptrace/bun/dialect/append.go +++ b/vendor/github.com/uptrace/bun/dialect/append.go @@ -95,9 +95,6 @@ func AppendBytes(b []byte, bytes []byte) []byte { } func AppendTime(b []byte, tm time.Time) []byte { - if tm.IsZero() { - return AppendNull(b) - } b = append(b, '\'') b = tm.UTC().AppendFormat(b, "2006-01-02 15:04:05.999999-07:00") b = append(b, '\'') diff --git a/vendor/github.com/uptrace/bun/hook.go b/vendor/github.com/uptrace/bun/hook.go index 88f8adbf2..ea6fc330b 100644 --- a/vendor/github.com/uptrace/bun/hook.go +++ b/vendor/github.com/uptrace/bun/hook.go @@ -53,7 +53,7 @@ func (db *DB) beforeQuery( query string, queryArgs []interface{}, ) (context.Context, *QueryEvent) { - atomic.AddUint64(&db.stats.Queries, 1) + atomic.AddUint32(&db.stats.Queries, 1) if len(db.queryHooks) == 0 { return ctx, nil @@ -86,7 +86,7 @@ func (db *DB) afterQuery( case nil, sql.ErrNoRows: // nothing default: - atomic.AddUint64(&db.stats.Errors, 1) + atomic.AddUint32(&db.stats.Errors, 1) } if event == nil { diff --git a/vendor/github.com/uptrace/bun/migrate/migration.go b/vendor/github.com/uptrace/bun/migrate/migration.go index 79f13f972..87881d6a2 100644 --- a/vendor/github.com/uptrace/bun/migrate/migration.go +++ b/vendor/github.com/uptrace/bun/migrate/migration.go @@ -190,7 +190,7 @@ func (ms MigrationSlice) LastGroupID() int64 { var lastGroupID int64 for i := range ms { groupID := ms[i].GroupID - if groupID != 0 && groupID > lastGroupID { + if groupID > lastGroupID { lastGroupID = groupID } } diff --git a/vendor/github.com/uptrace/bun/model_table_struct.go b/vendor/github.com/uptrace/bun/model_table_struct.go index ee207ea08..409d54326 100644 --- a/vendor/github.com/uptrace/bun/model_table_struct.go +++ b/vendor/github.com/uptrace/bun/model_table_struct.go @@ -216,6 +216,9 @@ func (m *structTableModel) join(bind reflect.Value, name string) *relationJoin { } func (m *structTableModel) updateSoftDeleteField(tm time.Time) error { + if !m.strct.IsValid() { + return nil + } fv := m.table.SoftDeleteField.Value(m.strct) return m.table.UpdateSoftDeleteField(fv, tm) } diff --git a/vendor/github.com/uptrace/bun/package.json b/vendor/github.com/uptrace/bun/package.json index a4651c19d..d9b4162e9 100644 --- a/vendor/github.com/uptrace/bun/package.json +++ b/vendor/github.com/uptrace/bun/package.json @@ -1,6 +1,6 @@ { "name": "bun", - "version": "1.0.6", + "version": "1.0.8", "main": "index.js", "repository": "git@github.com:uptrace/bun.git", "author": "Vladimir Mihailenco ", diff --git a/vendor/github.com/uptrace/bun/query_delete.go b/vendor/github.com/uptrace/bun/query_delete.go index 97b6dec7b..ef42e644e 100644 --- a/vendor/github.com/uptrace/bun/query_delete.go +++ b/vendor/github.com/uptrace/bun/query_delete.go @@ -155,7 +155,7 @@ func (q *DeleteQuery) AppendQuery(fmter schema.Formatter, b []byte) (_ []byte, e return upd.AppendQuery(fmter, b) } - q = q.WhereAllWithDeleted() + q = q.WhereDeleted() withAlias := q.db.features.Has(feature.DeleteTableAlias) b, err = q.appendWith(fmter, b) diff --git a/vendor/github.com/uptrace/bun/query_insert.go b/vendor/github.com/uptrace/bun/query_insert.go index 37daaf34a..e56089d24 100644 --- a/vendor/github.com/uptrace/bun/query_insert.go +++ b/vendor/github.com/uptrace/bun/query_insert.go @@ -431,9 +431,13 @@ func (q *InsertQuery) appendOn(fmter schema.Formatter, b []byte) (_ []byte, err b = q.appendSetExcluded(b, fields) } - b, err = q.appendWhere(fmter, b, true) - if err != nil { - return nil, err + if len(q.where) > 0 { + b = append(b, " WHERE "...) + + b, err = appendWhere(fmter, b, q.where) + if err != nil { + return nil, err + } } return b, nil diff --git a/vendor/github.com/uptrace/bun/query_select.go b/vendor/github.com/uptrace/bun/query_select.go index 28fafa92c..03f4bc04b 100644 --- a/vendor/github.com/uptrace/bun/query_select.go +++ b/vendor/github.com/uptrace/bun/query_select.go @@ -738,7 +738,7 @@ func (q *SelectQuery) afterSelectHook(ctx context.Context) error { func (q *SelectQuery) Count(ctx context.Context) (int, error) { qq := countQuery{q} - queryBytes, err := qq.appendQuery(q.db.fmter, nil, true) + queryBytes, err := qq.AppendQuery(q.db.fmter, nil) if err != nil { return 0, err } @@ -794,6 +794,25 @@ func (q *SelectQuery) ScanAndCount(ctx context.Context, dest ...interface{}) (in return count, firstErr } +func (q *SelectQuery) Exists(ctx context.Context) (bool, error) { + qq := existsQuery{q} + + queryBytes, err := qq.AppendQuery(q.db.fmter, nil) + if err != nil { + return false, err + } + + query := internal.String(queryBytes) + ctx, event := q.db.beforeQuery(ctx, qq, query, nil) + + var exists bool + err = q.conn.QueryRowContext(ctx, query).Scan(&exists) + + q.db.afterQuery(ctx, event, nil, err) + + return exists, err +} + //------------------------------------------------------------------------------ type joinQuery struct { @@ -837,3 +856,22 @@ type countQuery struct { func (q countQuery) AppendQuery(fmter schema.Formatter, b []byte) (_ []byte, err error) { return q.appendQuery(fmter, b, true) } + +//------------------------------------------------------------------------------ + +type existsQuery struct { + *SelectQuery +} + +func (q existsQuery) AppendQuery(fmter schema.Formatter, b []byte) (_ []byte, err error) { + b = append(b, "SELECT EXISTS ("...) + + b, err = q.appendQuery(fmter, b, false) + if err != nil { + return nil, err + } + + b = append(b, ")"...) + + return b, nil +} diff --git a/vendor/github.com/uptrace/bun/query_update.go b/vendor/github.com/uptrace/bun/query_update.go index ed387ecad..a5d9a17f2 100644 --- a/vendor/github.com/uptrace/bun/query_update.go +++ b/vendor/github.com/uptrace/bun/query_update.go @@ -170,8 +170,6 @@ func (q *UpdateQuery) AppendQuery(fmter schema.Formatter, b []byte) (_ []byte, e } fmter = formatterWithModel(fmter, q) - withAlias := fmter.HasFeature(feature.UpdateMultiTable) - b, err = q.appendWith(fmter, b) if err != nil { return nil, err @@ -179,7 +177,7 @@ func (q *UpdateQuery) AppendQuery(fmter schema.Formatter, b []byte) (_ []byte, e b = append(b, "UPDATE "...) - if withAlias { + if fmter.HasFeature(feature.UpdateMultiTable) { b, err = q.appendTablesWithAlias(fmter, b) } else { b, err = q.appendFirstTableWithAlias(fmter, b) @@ -200,7 +198,7 @@ func (q *UpdateQuery) AppendQuery(fmter schema.Formatter, b []byte) (_ []byte, e } } - b, err = q.mustAppendWhere(fmter, b, withAlias) + b, err = q.mustAppendWhere(fmter, b, true) if err != nil { return nil, err } diff --git a/vendor/github.com/uptrace/bun/schema/append.go b/vendor/github.com/uptrace/bun/schema/append.go index 68f7071c8..57d292bfe 100644 --- a/vendor/github.com/uptrace/bun/schema/append.go +++ b/vendor/github.com/uptrace/bun/schema/append.go @@ -3,29 +3,14 @@ package schema import ( "reflect" "strconv" - "strings" "time" "github.com/vmihailenco/msgpack/v5" "github.com/uptrace/bun/dialect" - "github.com/uptrace/bun/dialect/sqltype" "github.com/uptrace/bun/internal" ) -func FieldAppender(dialect Dialect, field *Field) AppenderFunc { - if field.Tag.HasOption("msgpack") { - return appendMsgpack - } - - switch strings.ToUpper(field.UserSQLType) { - case sqltype.JSON, sqltype.JSONB: - return AppendJSONValue - } - - return dialect.Appender(field.StructField.Type) -} - func Append(fmter Formatter, b []byte, v interface{}, custom CustomAppender) []byte { switch v := v.(type) { case nil: diff --git a/vendor/github.com/uptrace/bun/schema/append_value.go b/vendor/github.com/uptrace/bun/schema/append_value.go index 948ff86af..8fe8a13b2 100644 --- a/vendor/github.com/uptrace/bun/schema/append_value.go +++ b/vendor/github.com/uptrace/bun/schema/append_value.go @@ -6,9 +6,11 @@ import ( "net" "reflect" "strconv" + "strings" "time" "github.com/uptrace/bun/dialect" + "github.com/uptrace/bun/dialect/sqltype" "github.com/uptrace/bun/extra/bunjson" "github.com/uptrace/bun/internal" ) @@ -47,6 +49,19 @@ var appenders = []AppenderFunc{ reflect.UnsafePointer: nil, } +func FieldAppender(dialect Dialect, field *Field) AppenderFunc { + if field.Tag.HasOption("msgpack") { + return appendMsgpack + } + + switch strings.ToUpper(field.UserSQLType) { + case sqltype.JSON, sqltype.JSONB: + return AppendJSONValue + } + + return dialect.Appender(field.StructField.Type) +} + func Appender(typ reflect.Type, custom CustomAppender) AppenderFunc { switch typ { case bytesType: diff --git a/vendor/github.com/uptrace/bun/schema/field.go b/vendor/github.com/uptrace/bun/schema/field.go index 1e069b82f..59990b924 100644 --- a/vendor/github.com/uptrace/bun/schema/field.go +++ b/vendor/github.com/uptrace/bun/schema/field.go @@ -101,7 +101,9 @@ func (f *Field) ScanValue(strct reflect.Value, src interface{}) error { func (f *Field) markAsPK() { f.IsPK = true f.NotNull = true - f.NullZero = true + if !f.Tag.HasOption("allowzero") { + f.NullZero = true + } } func indexEqual(ind1, ind2 []int) bool { diff --git a/vendor/github.com/uptrace/bun/schema/scan.go b/vendor/github.com/uptrace/bun/schema/scan.go index 238fde217..60ad27d53 100644 --- a/vendor/github.com/uptrace/bun/schema/scan.go +++ b/vendor/github.com/uptrace/bun/schema/scan.go @@ -207,6 +207,9 @@ func scanString(dest reflect.Value, src interface{}) error { case []byte: dest.SetString(string(src)) return nil + case time.Time: + dest.SetString(src.Format(time.RFC3339Nano)) + return nil } return fmt.Errorf("bun: can't scan %#v into %s", src, dest.Type()) } diff --git a/vendor/github.com/uptrace/bun/schema/sqltype.go b/vendor/github.com/uptrace/bun/schema/sqltype.go index 23322a1e1..72609cf7a 100644 --- a/vendor/github.com/uptrace/bun/schema/sqltype.go +++ b/vendor/github.com/uptrace/bun/schema/sqltype.go @@ -109,17 +109,23 @@ func (tm *NullTime) Scan(src interface{}) error { } switch src := src.(type) { + case time.Time: + tm.Time = src + return nil + case string: + newtm, err := internal.ParseTime(src) + if err != nil { + return err + } + tm.Time = newtm + return nil case []byte: newtm, err := internal.ParseTime(internal.String(src)) if err != nil { return err } - tm.Time = newtm return nil - case time.Time: - tm.Time = src - return nil default: return fmt.Errorf("bun: can't scan %#v into NullTime", src) } diff --git a/vendor/github.com/uptrace/bun/schema/table.go b/vendor/github.com/uptrace/bun/schema/table.go index 8bed5ed38..213f821ab 100644 --- a/vendor/github.com/uptrace/bun/schema/table.go +++ b/vendor/github.com/uptrace/bun/schema/table.go @@ -181,17 +181,17 @@ func (t *Table) initFields() { t.FieldMap = make(map[string]*Field, t.Type.NumField()) t.addFields(t.Type, nil) - if len(t.PKs) > 0 { - return - } - for _, name := range []string{"id", "uuid", "pk_" + t.ModelName} { - if field, ok := t.FieldMap[name]; ok { - field.markAsPK() - t.PKs = []*Field{field} - t.DataFields = removeField(t.DataFields, field) - break + if len(t.PKs) == 0 { + for _, name := range []string{"id", "uuid", "pk_" + t.ModelName} { + if field, ok := t.FieldMap[name]; ok { + field.markAsPK() + t.PKs = []*Field{field} + t.DataFields = removeField(t.DataFields, field) + break + } } } + if len(t.PKs) == 1 { pk := t.PKs[0] if pk.SQLDefault != "" { diff --git a/vendor/github.com/uptrace/bun/version.go b/vendor/github.com/uptrace/bun/version.go index f81c108fd..3ce6d6692 100644 --- a/vendor/github.com/uptrace/bun/version.go +++ b/vendor/github.com/uptrace/bun/version.go @@ -2,5 +2,5 @@ package bun // Version is the current release version. func Version() string { - return "1.0.6" + return "1.0.8" } diff --git a/vendor/modules.txt b/vendor/modules.txt index ccfb67854..ce74678ab 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -447,7 +447,7 @@ github.com/tmthrgd/go-hex # github.com/ugorji/go/codec v1.2.6 ## explicit; go 1.11 github.com/ugorji/go/codec -# github.com/uptrace/bun v1.0.6 +# github.com/uptrace/bun v1.0.9-0.20210922104131-34c982b23581 ## explicit; go 1.16 github.com/uptrace/bun github.com/uptrace/bun/dialect @@ -459,10 +459,10 @@ 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.0.5 +# github.com/uptrace/bun/dialect/pgdialect v1.0.9-0.20210922104131-34c982b23581 ## explicit; go 1.16 github.com/uptrace/bun/dialect/pgdialect -# github.com/uptrace/bun/dialect/sqlitedialect v1.0.5 +# github.com/uptrace/bun/dialect/sqlitedialect v1.0.9-0.20210922104131-34c982b23581 ## explicit; go 1.16 github.com/uptrace/bun/dialect/sqlitedialect # github.com/urfave/cli/v2 v2.3.0