summaryrefslogtreecommitdiff
path: root/vendor/github.com/uptrace
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/uptrace')
-rw-r--r--vendor/github.com/uptrace/bun/CHANGELOG.md23
-rw-r--r--vendor/github.com/uptrace/bun/README.md141
-rw-r--r--vendor/github.com/uptrace/bun/db.go62
-rw-r--r--vendor/github.com/uptrace/bun/hook.go7
-rw-r--r--vendor/github.com/uptrace/bun/migrate/migrator.go55
-rw-r--r--vendor/github.com/uptrace/bun/package.json2
-rw-r--r--vendor/github.com/uptrace/bun/query_base.go95
-rw-r--r--vendor/github.com/uptrace/bun/query_column_add.go4
-rw-r--r--vendor/github.com/uptrace/bun/query_column_drop.go4
-rw-r--r--vendor/github.com/uptrace/bun/query_delete.go8
-rw-r--r--vendor/github.com/uptrace/bun/query_index_create.go4
-rw-r--r--vendor/github.com/uptrace/bun/query_index_drop.go7
-rw-r--r--vendor/github.com/uptrace/bun/query_insert.go8
-rw-r--r--vendor/github.com/uptrace/bun/query_select.go38
-rw-r--r--vendor/github.com/uptrace/bun/query_table_create.go4
-rw-r--r--vendor/github.com/uptrace/bun/query_table_drop.go9
-rw-r--r--vendor/github.com/uptrace/bun/query_table_truncate.go7
-rw-r--r--vendor/github.com/uptrace/bun/query_update.go8
-rw-r--r--vendor/github.com/uptrace/bun/query_values.go5
-rw-r--r--vendor/github.com/uptrace/bun/schema/formatter.go6
-rw-r--r--vendor/github.com/uptrace/bun/schema/table.go48
-rw-r--r--vendor/github.com/uptrace/bun/version.go2
22 files changed, 387 insertions, 160 deletions
diff --git a/vendor/github.com/uptrace/bun/CHANGELOG.md b/vendor/github.com/uptrace/bun/CHANGELOG.md
index 2b1082c5a..d58f28b0d 100644
--- a/vendor/github.com/uptrace/bun/CHANGELOG.md
+++ b/vendor/github.com/uptrace/bun/CHANGELOG.md
@@ -1,3 +1,26 @@
+## [1.0.20](https://github.com/uptrace/bun/compare/v1.0.19...v1.0.20) (2021-12-19)
+
+
+### Bug Fixes
+
+* add Event.QueryTemplate and change Event.Query to be always formatted ([52b1ccd](https://github.com/uptrace/bun/commit/52b1ccdf3578418aa427adef9dcf942d90ae4fdd))
+* change GetTableName to return formatted table name in case ModelTableExpr ([95144dd](https://github.com/uptrace/bun/commit/95144dde937b4ac88b36b0bd8b01372421069b44))
+* change ScanAndCount to work with transactions ([5b3f2c0](https://github.com/uptrace/bun/commit/5b3f2c021c424da366caffd33589e8adde821403))
+* **dbfixture:** directly call funcs bypassing template eval ([a61974b](https://github.com/uptrace/bun/commit/a61974ba2d24361c5357fb9bda1f3eceec5a45cd))
+* don't append CASCADE by default in drop table/column queries ([26457ea](https://github.com/uptrace/bun/commit/26457ea5cb20862d232e6e5fa4dbdeac5d444bf1))
+* **migrate:** mark migrations as applied on error so the migration can be rolled back ([8ce33fb](https://github.com/uptrace/bun/commit/8ce33fbbac8e33077c20daf19a14c5ff2291bcae))
+* respect nullzero when appending struct fields. Fixes [#339](https://github.com/uptrace/bun/issues/339) ([ffd02f3](https://github.com/uptrace/bun/commit/ffd02f3170b3cccdd670a48d563cfb41094c05d6))
+* reuse tx for relation join ([#366](https://github.com/uptrace/bun/issues/366)) ([60bdb1a](https://github.com/uptrace/bun/commit/60bdb1ac84c0a699429eead3b7fdfbf14fe69ac6))
+
+
+### Features
+
+* add `Dialect()` to Transaction and IDB interface ([693f1e1](https://github.com/uptrace/bun/commit/693f1e135999fc31cf83b99a2530a695b20f4e1b))
+* add model embedding via embed:prefix_ ([9a2cedc](https://github.com/uptrace/bun/commit/9a2cedc8b08fa8585d4bfced338bd0a40d736b1d))
+* change the default logoutput to stderr ([4bf5773](https://github.com/uptrace/bun/commit/4bf577382f19c64457cbf0d64490401450954654)), closes [#349](https://github.com/uptrace/bun/issues/349)
+
+
+
## [1.0.19](https://github.com/uptrace/bun/compare/v1.0.18...v1.0.19) (2021-11-30)
diff --git a/vendor/github.com/uptrace/bun/README.md b/vendor/github.com/uptrace/bun/README.md
index 2eeff3bc1..d3de3769b 100644
--- a/vendor/github.com/uptrace/bun/README.md
+++ b/vendor/github.com/uptrace/bun/README.md
@@ -43,8 +43,147 @@ Projects using Bun:
demand.
- [RealWorld app](https://github.com/go-bun/bun-realworld-app)
+## Benchmark
+[https://github.com/davars/dbeval](https://github.com/davars/dbeval)
<details>
- <summary>github.com/frederikhors/orm-benchmark results</summary>
+<summary>results</summary>
+
+```
+BenchmarkInsert
+BenchmarkInsert/*dbeval.Memory/Authors
+BenchmarkInsert/*dbeval.Memory/Authors-4 84450 12104 ns/op 2623 B/op 70 allocs/op
+BenchmarkInsert/*dbeval.Xorm/Authors
+BenchmarkInsert/*dbeval.Xorm/Authors-4 7291 153505 ns/op 9024 B/op 311 allocs/op
+BenchmarkInsert/*dbeval.UpperDB/Authors
+BenchmarkInsert/*dbeval.UpperDB/Authors-4 4608 223672 ns/op 24160 B/op 1100 allocs/op
+BenchmarkInsert/*dbeval.Bun/Authors
+BenchmarkInsert/*dbeval.Bun/Authors-4 6034 186439 ns/op 6818 B/op 80 allocs/op
+BenchmarkInsert/*dbeval.PQ/Authors
+BenchmarkInsert/*dbeval.PQ/Authors-4 1141 907494 ns/op 6487 B/op 193 allocs/op
+BenchmarkInsert/*dbeval.SQLX/Authors
+BenchmarkInsert/*dbeval.SQLX/Authors-4 1165 916987 ns/op 10089 B/op 271 allocs/op
+BenchmarkInsert/*dbeval.Ozzo/Authors
+BenchmarkInsert/*dbeval.Ozzo/Authors-4 1105 1058082 ns/op 27826 B/op 588 allocs/op
+BenchmarkInsert/*dbeval.PGXStdlib/Authors
+BenchmarkInsert/*dbeval.PGXStdlib/Authors-4 1228 900207 ns/op 6032 B/op 180 allocs/op
+BenchmarkInsert/*dbeval.Gorm/Authors
+BenchmarkInsert/*dbeval.Gorm/Authors-4 946 1184285 ns/op 35634 B/op 918 allocs/op
+BenchmarkInsert/*dbeval.PGX/Authors
+BenchmarkInsert/*dbeval.PGX/Authors-4 1116 923728 ns/op 3839 B/op 130 allocs/op
+BenchmarkInsert/*dbeval.DBR/Authors
+BenchmarkInsert/*dbeval.DBR/Authors-4 5800 183982 ns/op 8646 B/op 230 allocs/op
+BenchmarkInsert/*dbeval.GoPG/Authors
+BenchmarkInsert/*dbeval.GoPG/Authors-4 6110 173923 ns/op 2906 B/op 87 allocs/op
+
+BenchmarkInsert/*dbeval.DBR/Articles
+BenchmarkInsert/*dbeval.DBR/Articles-4 1706 684466 ns/op 133346 B/op 1614 allocs/op
+BenchmarkInsert/*dbeval.PQ/Articles
+BenchmarkInsert/*dbeval.PQ/Articles-4 884 1249791 ns/op 100403 B/op 1491 allocs/op
+BenchmarkInsert/*dbeval.PGX/Articles
+BenchmarkInsert/*dbeval.PGX/Articles-4 916 1288143 ns/op 83539 B/op 1392 allocs/op
+BenchmarkInsert/*dbeval.GoPG/Articles
+BenchmarkInsert/*dbeval.GoPG/Articles-4 1726 622639 ns/op 78638 B/op 1359 allocs/op
+BenchmarkInsert/*dbeval.SQLX/Articles
+BenchmarkInsert/*dbeval.SQLX/Articles-4 860 1262599 ns/op 92030 B/op 1574 allocs/op
+BenchmarkInsert/*dbeval.Gorm/Articles
+BenchmarkInsert/*dbeval.Gorm/Articles-4 782 1421550 ns/op 136534 B/op 2411 allocs/op
+BenchmarkInsert/*dbeval.PGXStdlib/Articles
+BenchmarkInsert/*dbeval.PGXStdlib/Articles-4 938 1230576 ns/op 86743 B/op 1441 allocs/op
+BenchmarkInsert/*dbeval.Bun/Articles
+BenchmarkInsert/*dbeval.Bun/Articles-4 1843 626681 ns/op 101610 B/op 1323 allocs/op
+BenchmarkInsert/*dbeval.Xorm/Articles
+BenchmarkInsert/*dbeval.Xorm/Articles-4 1677 650244 ns/op 126677 B/op 1752 allocs/op
+BenchmarkInsert/*dbeval.Memory/Articles
+BenchmarkInsert/*dbeval.Memory/Articles-4 1988 1223308 ns/op 77576 B/op 1310 allocs/op
+BenchmarkInsert/*dbeval.UpperDB/Articles
+BenchmarkInsert/*dbeval.UpperDB/Articles-4 1696 687130 ns/op 139680 B/op 2862 allocs/op
+BenchmarkInsert/*dbeval.Ozzo/Articles
+BenchmarkInsert/*dbeval.Ozzo/Articles-4 697 1496859 ns/op 114780 B/op 1950 allocs/op
+
+BenchmarkFindAuthorByID
+BenchmarkFindAuthorByID/*dbeval.UpperDB
+BenchmarkFindAuthorByID/*dbeval.UpperDB-4 10184 117527 ns/op 9953 B/op 441 allocs/op
+BenchmarkFindAuthorByID/*dbeval.Bun
+BenchmarkFindAuthorByID/*dbeval.Bun-4 20716 54261 ns/op 5096 B/op 15 allocs/op
+BenchmarkFindAuthorByID/*dbeval.Ozzo
+BenchmarkFindAuthorByID/*dbeval.Ozzo-4 11166 91043 ns/op 3088 B/op 64 allocs/op
+BenchmarkFindAuthorByID/*dbeval.PQ
+BenchmarkFindAuthorByID/*dbeval.PQ-4 13875 86171 ns/op 844 B/op 24 allocs/op
+BenchmarkFindAuthorByID/*dbeval.PGX
+BenchmarkFindAuthorByID/*dbeval.PGX-4 13846 79983 ns/op 719 B/op 15 allocs/op
+BenchmarkFindAuthorByID/*dbeval.Memory
+BenchmarkFindAuthorByID/*dbeval.Memory-4 14113720 82.33 ns/op 0 B/op 0 allocs/op
+BenchmarkFindAuthorByID/*dbeval.Xorm
+BenchmarkFindAuthorByID/*dbeval.Xorm-4 12027 98519 ns/op 3633 B/op 106 allocs/op
+BenchmarkFindAuthorByID/*dbeval.Gorm
+BenchmarkFindAuthorByID/*dbeval.Gorm-4 11521 102241 ns/op 6592 B/op 143 allocs/op
+BenchmarkFindAuthorByID/*dbeval.PGXStdlib
+BenchmarkFindAuthorByID/*dbeval.PGXStdlib-4 13933 82626 ns/op 1174 B/op 28 allocs/op
+BenchmarkFindAuthorByID/*dbeval.DBR
+BenchmarkFindAuthorByID/*dbeval.DBR-4 21920 51175 ns/op 1756 B/op 39 allocs/op
+BenchmarkFindAuthorByID/*dbeval.SQLX
+BenchmarkFindAuthorByID/*dbeval.SQLX-4 13603 80788 ns/op 1327 B/op 32 allocs/op
+BenchmarkFindAuthorByID/*dbeval.GoPG
+BenchmarkFindAuthorByID/*dbeval.GoPG-4 23174 50042 ns/op 869 B/op 17 allocs/op
+
+BenchmarkFindAuthorByName
+BenchmarkFindAuthorByName/*dbeval.SQLX
+BenchmarkFindAuthorByName/*dbeval.SQLX-4 1070 1065272 ns/op 126348 B/op 4018 allocs/op
+BenchmarkFindAuthorByName/*dbeval.Bun
+BenchmarkFindAuthorByName/*dbeval.Bun-4 877 1231377 ns/op 115803 B/op 5005 allocs/op
+BenchmarkFindAuthorByName/*dbeval.Xorm
+BenchmarkFindAuthorByName/*dbeval.Xorm-4 471 2345445 ns/op 455711 B/op 19080 allocs/op
+BenchmarkFindAuthorByName/*dbeval.DBR
+BenchmarkFindAuthorByName/*dbeval.DBR-4 954 1089977 ns/op 120070 B/op 6023 allocs/op
+BenchmarkFindAuthorByName/*dbeval.PQ
+BenchmarkFindAuthorByName/*dbeval.PQ-4 1333 784400 ns/op 87159 B/op 4006 allocs/op
+BenchmarkFindAuthorByName/*dbeval.GoPG
+BenchmarkFindAuthorByName/*dbeval.GoPG-4 1580 770966 ns/op 87525 B/op 3028 allocs/op
+BenchmarkFindAuthorByName/*dbeval.UpperDB
+BenchmarkFindAuthorByName/*dbeval.UpperDB-4 789 1314164 ns/op 190689 B/op 6428 allocs/op
+BenchmarkFindAuthorByName/*dbeval.Ozzo
+BenchmarkFindAuthorByName/*dbeval.Ozzo-4 948 1255282 ns/op 238764 B/op 6053 allocs/op
+BenchmarkFindAuthorByName/*dbeval.PGXStdlib
+BenchmarkFindAuthorByName/*dbeval.PGXStdlib-4 1279 920391 ns/op 126163 B/op 4014 allocs/op
+BenchmarkFindAuthorByName/*dbeval.PGX
+BenchmarkFindAuthorByName/*dbeval.PGX-4 1364 780970 ns/op 101967 B/op 2028 allocs/op
+BenchmarkFindAuthorByName/*dbeval.Gorm
+BenchmarkFindAuthorByName/*dbeval.Gorm-4 340 3445818 ns/op 1573637 B/op 27102 allocs/op
+BenchmarkFindAuthorByName/*dbeval.Memory
+BenchmarkFindAuthorByName/*dbeval.Memory-4 38081223 31.24 ns/op 0 B/op 0 allocs/op
+
+BenchmarkRecentArticles
+BenchmarkRecentArticles/*dbeval.PGXStdlib
+BenchmarkRecentArticles/*dbeval.PGXStdlib-4 358 3344119 ns/op 3425578 B/op 14177 allocs/op
+BenchmarkRecentArticles/*dbeval.GoPG
+BenchmarkRecentArticles/*dbeval.GoPG-4 364 3156372 ns/op 1794091 B/op 10032 allocs/op
+BenchmarkRecentArticles/*dbeval.Xorm
+BenchmarkRecentArticles/*dbeval.Xorm-4 157 7567835 ns/op 5018011 B/op 81425 allocs/op
+BenchmarkRecentArticles/*dbeval.Gorm
+BenchmarkRecentArticles/*dbeval.Gorm-4 139 7980084 ns/op 6776277 B/op 85418 allocs/op
+BenchmarkRecentArticles/*dbeval.SQLX
+BenchmarkRecentArticles/*dbeval.SQLX-4 338 3289802 ns/op 3425890 B/op 14181 allocs/op
+BenchmarkRecentArticles/*dbeval.Ozzo
+BenchmarkRecentArticles/*dbeval.Ozzo-4 320 3508322 ns/op 4025966 B/op 18207 allocs/op
+BenchmarkRecentArticles/*dbeval.DBR
+BenchmarkRecentArticles/*dbeval.DBR-4 237 5248644 ns/op 3331003 B/op 21370 allocs/op
+BenchmarkRecentArticles/*dbeval.Bun
+BenchmarkRecentArticles/*dbeval.Bun-4 280 4528582 ns/op 1864362 B/op 15965 allocs/op
+BenchmarkRecentArticles/*dbeval.UpperDB
+BenchmarkRecentArticles/*dbeval.UpperDB-4 297 3704663 ns/op 3607287 B/op 18542 allocs/op
+BenchmarkRecentArticles/*dbeval.PQ
+BenchmarkRecentArticles/*dbeval.PQ-4 308 3489229 ns/op 3277050 B/op 17359 allocs/op
+BenchmarkRecentArticles/*dbeval.Memory
+BenchmarkRecentArticles/*dbeval.Memory-4 29590380 42.27 ns/op 0 B/op 0 allocs/op
+BenchmarkRecentArticles/*dbeval.PGX
+BenchmarkRecentArticles/*dbeval.PGX-4 356 3345500 ns/op 3297316 B/op 6226 allocs/op
+```
+
+</details>
+
+[https://github.com/frederikhors/orm-benchmark](https://github.com/frederikhors/orm-benchmark)
+<details>
+<summary>results</summary>
```
4000 times - Insert
diff --git a/vendor/github.com/uptrace/bun/db.go b/vendor/github.com/uptrace/bun/db.go
index a83b07d35..78969c019 100644
--- a/vendor/github.com/uptrace/bun/db.go
+++ b/vendor/github.com/uptrace/bun/db.go
@@ -32,6 +32,7 @@ func WithDiscardUnknownColumns() DBOption {
type DB struct {
*sql.DB
+
dialect schema.Dialect
features feature.Feature
@@ -125,7 +126,7 @@ func (db *DB) NewDropColumn() *DropColumnQuery {
func (db *DB) ResetModel(ctx context.Context, models ...interface{}) error {
for _, model := range models {
- if _, err := db.NewDropTable().Model(model).IfExists().Exec(ctx); err != nil {
+ if _, err := db.NewDropTable().Model(model).IfExists().Cascade().Exec(ctx); err != nil {
return err
}
if _, err := db.NewCreateTable().Model(model).Exec(ctx); err != nil {
@@ -226,8 +227,9 @@ func (db *DB) Exec(query string, args ...interface{}) (sql.Result, error) {
func (db *DB) ExecContext(
ctx context.Context, query string, args ...interface{},
) (sql.Result, error) {
- ctx, event := db.beforeQuery(ctx, nil, query, args, nil)
- res, err := db.DB.ExecContext(ctx, db.format(query, args))
+ formattedQuery := db.format(query, args)
+ ctx, event := db.beforeQuery(ctx, nil, query, args, formattedQuery, nil)
+ res, err := db.DB.ExecContext(ctx, formattedQuery)
db.afterQuery(ctx, event, res, err)
return res, err
}
@@ -239,8 +241,9 @@ func (db *DB) Query(query string, args ...interface{}) (*sql.Rows, error) {
func (db *DB) QueryContext(
ctx context.Context, query string, args ...interface{},
) (*sql.Rows, error) {
- ctx, event := db.beforeQuery(ctx, nil, query, args, nil)
- rows, err := db.DB.QueryContext(ctx, db.format(query, args))
+ formattedQuery := db.format(query, args)
+ ctx, event := db.beforeQuery(ctx, nil, query, args, formattedQuery, nil)
+ rows, err := db.DB.QueryContext(ctx, formattedQuery)
db.afterQuery(ctx, event, nil, err)
return rows, err
}
@@ -250,8 +253,9 @@ func (db *DB) QueryRow(query string, args ...interface{}) *sql.Row {
}
func (db *DB) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row {
- ctx, event := db.beforeQuery(ctx, nil, query, args, nil)
- row := db.DB.QueryRowContext(ctx, db.format(query, args))
+ formattedQuery := db.format(query, args)
+ ctx, event := db.beforeQuery(ctx, nil, query, args, formattedQuery, nil)
+ row := db.DB.QueryRowContext(ctx, formattedQuery)
db.afterQuery(ctx, event, nil, row.Err())
return row
}
@@ -281,8 +285,9 @@ func (db *DB) Conn(ctx context.Context) (Conn, error) {
func (c Conn) ExecContext(
ctx context.Context, query string, args ...interface{},
) (sql.Result, error) {
- ctx, event := c.db.beforeQuery(ctx, nil, query, args, nil)
- res, err := c.Conn.ExecContext(ctx, c.db.format(query, args))
+ formattedQuery := c.db.format(query, args)
+ ctx, event := c.db.beforeQuery(ctx, nil, query, args, formattedQuery, nil)
+ res, err := c.Conn.ExecContext(ctx, formattedQuery)
c.db.afterQuery(ctx, event, res, err)
return res, err
}
@@ -290,19 +295,25 @@ func (c Conn) ExecContext(
func (c Conn) QueryContext(
ctx context.Context, query string, args ...interface{},
) (*sql.Rows, error) {
- ctx, event := c.db.beforeQuery(ctx, nil, query, args, nil)
- rows, err := c.Conn.QueryContext(ctx, c.db.format(query, args))
+ formattedQuery := c.db.format(query, args)
+ ctx, event := c.db.beforeQuery(ctx, nil, query, args, formattedQuery, nil)
+ rows, err := c.Conn.QueryContext(ctx, formattedQuery)
c.db.afterQuery(ctx, event, nil, err)
return rows, err
}
func (c Conn) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row {
- ctx, event := c.db.beforeQuery(ctx, nil, query, args, nil)
- row := c.Conn.QueryRowContext(ctx, c.db.format(query, args))
+ formattedQuery := c.db.format(query, args)
+ ctx, event := c.db.beforeQuery(ctx, nil, query, args, formattedQuery, nil)
+ row := c.Conn.QueryRowContext(ctx, formattedQuery)
c.db.afterQuery(ctx, event, nil, row.Err())
return row
}
+func (c Conn) Dialect() schema.Dialect {
+ return c.db.Dialect()
+}
+
func (c Conn) NewValues(model interface{}) *ValuesQuery {
return NewValuesQuery(c.db, model).Conn(c)
}
@@ -408,7 +419,7 @@ func (db *DB) Begin() (Tx, error) {
}
func (db *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (Tx, error) {
- ctx, event := db.beforeQuery(ctx, nil, "BEGIN", nil, nil)
+ ctx, event := db.beforeQuery(ctx, nil, "BEGIN", nil, "BEGIN", nil)
tx, err := db.DB.BeginTx(ctx, opts)
db.afterQuery(ctx, event, nil, err)
if err != nil {
@@ -422,14 +433,14 @@ func (db *DB) BeginTx(ctx context.Context, opts *sql.TxOptions) (Tx, error) {
}
func (tx Tx) Commit() error {
- ctx, event := tx.db.beforeQuery(tx.ctx, nil, "COMMIT", nil, nil)
+ ctx, event := tx.db.beforeQuery(tx.ctx, nil, "COMMIT", nil, "COMMIT", nil)
err := tx.Tx.Commit()
tx.db.afterQuery(ctx, event, nil, err)
return err
}
func (tx Tx) Rollback() error {
- ctx, event := tx.db.beforeQuery(tx.ctx, nil, "ROLLBACK", nil, nil)
+ ctx, event := tx.db.beforeQuery(tx.ctx, nil, "ROLLBACK", nil, "ROLLBACK", nil)
err := tx.Tx.Rollback()
tx.db.afterQuery(ctx, event, nil, err)
return err
@@ -442,8 +453,9 @@ func (tx Tx) Exec(query string, args ...interface{}) (sql.Result, error) {
func (tx Tx) ExecContext(
ctx context.Context, query string, args ...interface{},
) (sql.Result, error) {
- ctx, event := tx.db.beforeQuery(ctx, nil, query, args, nil)
- res, err := tx.Tx.ExecContext(ctx, tx.db.format(query, args))
+ formattedQuery := tx.db.format(query, args)
+ ctx, event := tx.db.beforeQuery(ctx, nil, query, args, formattedQuery, nil)
+ res, err := tx.Tx.ExecContext(ctx, formattedQuery)
tx.db.afterQuery(ctx, event, res, err)
return res, err
}
@@ -455,8 +467,9 @@ func (tx Tx) Query(query string, args ...interface{}) (*sql.Rows, error) {
func (tx Tx) QueryContext(
ctx context.Context, query string, args ...interface{},
) (*sql.Rows, error) {
- ctx, event := tx.db.beforeQuery(ctx, nil, query, args, nil)
- rows, err := tx.Tx.QueryContext(ctx, tx.db.format(query, args))
+ formattedQuery := tx.db.format(query, args)
+ ctx, event := tx.db.beforeQuery(ctx, nil, query, args, formattedQuery, nil)
+ rows, err := tx.Tx.QueryContext(ctx, formattedQuery)
tx.db.afterQuery(ctx, event, nil, err)
return rows, err
}
@@ -466,14 +479,19 @@ func (tx Tx) QueryRow(query string, args ...interface{}) *sql.Row {
}
func (tx Tx) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row {
- ctx, event := tx.db.beforeQuery(ctx, nil, query, args, nil)
- row := tx.Tx.QueryRowContext(ctx, tx.db.format(query, args))
+ formattedQuery := tx.db.format(query, args)
+ ctx, event := tx.db.beforeQuery(ctx, nil, query, args, formattedQuery, nil)
+ row := tx.Tx.QueryRowContext(ctx, formattedQuery)
tx.db.afterQuery(ctx, event, nil, row.Err())
return row
}
//------------------------------------------------------------------------------
+func (tx Tx) Dialect() schema.Dialect {
+ return tx.db.Dialect()
+}
+
func (tx Tx) NewValues(model interface{}) *ValuesQuery {
return NewValuesQuery(tx.db, model).Conn(tx)
}
diff --git a/vendor/github.com/uptrace/bun/hook.go b/vendor/github.com/uptrace/bun/hook.go
index 7cca7ef6a..81249329a 100644
--- a/vendor/github.com/uptrace/bun/hook.go
+++ b/vendor/github.com/uptrace/bun/hook.go
@@ -13,9 +13,10 @@ import (
type QueryEvent struct {
DB *DB
- QueryAppender schema.QueryAppender // Deprecated: use IQuery instead
+ QueryAppender schema.QueryAppender // DEPRECATED: use IQuery instead
IQuery Query
Query string
+ QueryTemplate string
QueryArgs []interface{}
Model Model
@@ -51,8 +52,9 @@ type QueryHook interface {
func (db *DB) beforeQuery(
ctx context.Context,
iquery Query,
- query string,
+ queryTemplate string,
queryArgs []interface{},
+ query string,
model Model,
) (context.Context, *QueryEvent) {
atomic.AddUint32(&db.stats.Queries, 1)
@@ -68,6 +70,7 @@ func (db *DB) beforeQuery(
QueryAppender: iquery,
IQuery: iquery,
Query: query,
+ QueryTemplate: queryTemplate,
QueryArgs: queryArgs,
StartTime: time.Now(),
diff --git a/vendor/github.com/uptrace/bun/migrate/migrator.go b/vendor/github.com/uptrace/bun/migrate/migrator.go
index 1808d9db8..9c8d44173 100644
--- a/vendor/github.com/uptrace/bun/migrate/migrator.go
+++ b/vendor/github.com/uptrace/bun/migrate/migrator.go
@@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io/ioutil"
- "log"
"path/filepath"
"regexp"
"time"
@@ -59,11 +58,16 @@ func (m *Migrator) DB() *bun.DB {
// MigrationsWithStatus returns migrations with status in ascending order.
func (m *Migrator) MigrationsWithStatus(ctx context.Context) (MigrationSlice, error) {
+ sorted, _, err := m.migrationsWithStatus(ctx)
+ return sorted, err
+}
+
+func (m *Migrator) migrationsWithStatus(ctx context.Context) (MigrationSlice, int64, error) {
sorted := m.migrations.Sorted()
applied, err := m.selectAppliedMigrations(ctx)
if err != nil {
- return nil, err
+ return nil, 0, err
}
appliedMap := migrationMap(applied)
@@ -76,7 +80,7 @@ func (m *Migrator) MigrationsWithStatus(ctx context.Context) (MigrationSlice, er
}
}
- return sorted, nil
+ return sorted, applied.LastGroupID(), nil
}
func (m *Migrator) Init(ctx context.Context) error {
@@ -128,7 +132,7 @@ func (m *Migrator) Migrate(ctx context.Context, opts ...MigrationOption) (*Migra
}
defer m.Unlock(ctx) //nolint:errcheck
- migrations, err := m.MigrationsWithStatus(ctx)
+ migrations, lastGroupID, err := m.migrationsWithStatus(ctx)
if err != nil {
return nil, err
}
@@ -139,21 +143,22 @@ func (m *Migrator) Migrate(ctx context.Context, opts ...MigrationOption) (*Migra
if len(group.Migrations) == 0 {
return group, nil
}
- group.ID = migrations.LastGroupID() + 1
+ group.ID = lastGroupID + 1
for i := range group.Migrations {
migration := &group.Migrations[i]
migration.GroupID = group.ID
+ // Always mark migration as applied so the rollback has a chance to fix the database.
+ if err := m.MarkApplied(ctx, migration); err != nil {
+ return nil, err
+ }
+
if !cfg.nop && migration.Up != nil {
if err := migration.Up(ctx, m.db); err != nil {
return group, err
}
}
-
- if err := m.MarkApplied(ctx, migration); err != nil {
- return nil, err
- }
}
return group, nil
@@ -195,36 +200,6 @@ func (m *Migrator) Rollback(ctx context.Context, opts ...MigrationOption) (*Migr
return lastGroup, nil
}
-type MigrationStatus struct {
- Migrations MigrationSlice
- NewMigrations MigrationSlice
- LastGroup *MigrationGroup
-}
-
-func (m *Migrator) Status(ctx context.Context) (*MigrationStatus, error) {
- log.Printf(
- "DEPRECATED: bun: replace Status(ctx) with " +
- "MigrationsWithStatus(ctx)")
-
- migrations, err := m.MigrationsWithStatus(ctx)
- if err != nil {
- return nil, err
- }
- return &MigrationStatus{
- Migrations: migrations,
- NewMigrations: migrations.Unapplied(),
- LastGroup: migrations.LastGroup(),
- }, nil
-}
-
-func (m *Migrator) MarkCompleted(ctx context.Context) (*MigrationGroup, error) {
- log.Printf(
- "DEPRECATED: bun: replace MarkCompleted(ctx) with " +
- "Migrate(ctx, migrate.WithNopMigration())")
-
- return m.Migrate(ctx, WithNopMigration())
-}
-
type goMigrationConfig struct {
packageName string
}
@@ -320,7 +295,7 @@ func (m *Migrator) genMigrationName(name string) (string, error) {
return fmt.Sprintf("%s_%s", version, name), nil
}
-// MarkApplied marks the migration as applied (applied).
+// MarkApplied marks the migration as applied (completed).
func (m *Migrator) MarkApplied(ctx context.Context, migration *Migration) error {
_, err := m.db.NewInsert().Model(migration).
ModelTableExpr(m.table).
diff --git a/vendor/github.com/uptrace/bun/package.json b/vendor/github.com/uptrace/bun/package.json
index 50f48e152..2e1b77991 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.19",
+ "version": "1.0.20",
"main": "index.js",
"repository": "git@github.com:uptrace/bun.git",
"author": "Vladimir Mihailenco <vladimir.webdev@gmail.com>",
diff --git a/vendor/github.com/uptrace/bun/query_base.go b/vendor/github.com/uptrace/bun/query_base.go
index 4cf31d04e..8b78d25e1 100644
--- a/vendor/github.com/uptrace/bun/query_base.go
+++ b/vendor/github.com/uptrace/bun/query_base.go
@@ -43,6 +43,7 @@ var (
// IDB is a common interface for *bun.DB, bun.Conn, and bun.Tx.
type IDB interface {
IConn
+ Dialect() schema.Dialect
NewValues(model interface{}) *ValuesQuery
NewSelect() *SelectQuery
@@ -59,9 +60,9 @@ type IDB interface {
}
var (
- _ IConn = (*DB)(nil)
- _ IConn = (*Conn)(nil)
- _ IConn = (*Tx)(nil)
+ _ IDB = (*DB)(nil)
+ _ IDB = (*Conn)(nil)
+ _ IDB = (*Tx)(nil)
)
type baseQuery struct {
@@ -74,10 +75,10 @@ type baseQuery struct {
tableModel TableModel
table *schema.Table
- with []withQuery
- modelTable schema.QueryWithArgs
- tables []schema.QueryWithArgs
- columns []schema.QueryWithArgs
+ with []withQuery
+ modelTableName schema.QueryWithArgs
+ tables []schema.QueryWithArgs
+ columns []schema.QueryWithArgs
flags internal.Flag
}
@@ -86,13 +87,6 @@ func (q *baseQuery) DB() *DB {
return q.db
}
-type query interface {
- GetModel() Model
- GetTableName() string
-}
-
-var _ query = (*baseQuery)(nil)
-
func (q *baseQuery) GetModel() Model {
return q.model
}
@@ -103,15 +97,16 @@ func (q *baseQuery) GetTableName() string {
}
for _, wq := range q.with {
- if v, ok := wq.query.(query); ok {
+ if v, ok := wq.query.(Query); ok {
if model := v.GetModel(); model != nil {
return v.GetTableName()
}
}
}
- if q.modelTable.Query != "" {
- return q.modelTable.Query
+ if q.modelTableName.Query != "" {
+ b, _ := q.modelTableName.AppendQuery(q.db.fmter, nil)
+ return string(b)
}
if len(q.tables) > 0 {
return q.tables[0].Query
@@ -304,8 +299,8 @@ func (q *baseQuery) _excludeColumn(column string) bool {
//------------------------------------------------------------------------------
func (q *baseQuery) modelHasTableName() bool {
- if !q.modelTable.IsZero() {
- return q.modelTable.Query != ""
+ if !q.modelTableName.IsZero() {
+ return q.modelTableName.Query != ""
}
return q.table != nil
}
@@ -332,8 +327,8 @@ func (q *baseQuery) _appendTables(
startLen := len(b)
if q.modelHasTableName() {
- if !q.modelTable.IsZero() {
- b, err = q.modelTable.AppendQuery(fmter, b)
+ if !q.modelTableName.IsZero() {
+ b, err = q.modelTableName.AppendQuery(fmter, b)
if err != nil {
return nil, err
}
@@ -372,8 +367,8 @@ func (q *baseQuery) appendFirstTableWithAlias(
func (q *baseQuery) _appendFirstTable(
fmter schema.Formatter, b []byte, withAlias bool,
) ([]byte, error) {
- if !q.modelTable.IsZero() {
- return q.modelTable.AppendQuery(fmter, b)
+ if !q.modelTableName.IsZero() {
+ return q.modelTableName.AppendQuery(fmter, b)
}
if q.table != nil {
@@ -473,7 +468,7 @@ func (q *baseQuery) scan(
model Model,
hasDest bool,
) (sql.Result, error) {
- ctx, event := q.db.beforeQuery(ctx, iquery, query, nil, q.model)
+ ctx, event := q.db.beforeQuery(ctx, iquery, query, nil, query, q.model)
rows, err := q.conn.QueryContext(ctx, query)
if err != nil {
@@ -503,16 +498,10 @@ func (q *baseQuery) exec(
iquery Query,
query string,
) (sql.Result, error) {
- ctx, event := q.db.beforeQuery(ctx, iquery, query, nil, q.model)
-
+ ctx, event := q.db.beforeQuery(ctx, iquery, query, nil, query, q.model)
res, err := q.conn.ExecContext(ctx, query)
- if err != nil {
- q.db.afterQuery(ctx, event, nil, err)
- return res, err
- }
-
- q.db.afterQuery(ctx, event, res, err)
- return res, nil
+ q.db.afterQuery(ctx, event, nil, err)
+ return res, err
}
//------------------------------------------------------------------------------
@@ -607,34 +596,30 @@ func (q *whereBaseQuery) addWhereCols(cols []string) {
q.setErr(err)
return
}
-
- var fields []*schema.Field
+ if q.whereFields != nil {
+ err := errors.New("bun: WherePK can only be called once")
+ q.setErr(err)
+ return
+ }
if cols == nil {
if err := q.table.CheckPKs(); err != nil {
q.setErr(err)
return
}
- fields = q.table.PKs
- } else {
- fields = make([]*schema.Field, len(cols))
- for i, col := range cols {
- field, err := q.table.Field(col)
- if err != nil {
- q.setErr(err)
- return
- }
- fields[i] = field
- }
- }
-
- if q.whereFields != nil {
- err := errors.New("bun: WherePK can only be called once")
- q.setErr(err)
+ q.whereFields = q.table.PKs
return
}
- q.whereFields = fields
+ q.whereFields = make([]*schema.Field, len(cols))
+ for i, col := range cols {
+ field, err := q.table.Field(col)
+ if err != nil {
+ q.setErr(err)
+ return
+ }
+ q.whereFields[i] = field
+ }
}
func (q *whereBaseQuery) mustAppendWhere(
@@ -951,6 +936,7 @@ func (q setQuery) appendSet(fmter schema.Formatter, b []byte) (_ []byte, err err
//------------------------------------------------------------------------------
type cascadeQuery struct {
+ cascade bool
restrict bool
}
@@ -958,10 +944,11 @@ func (q cascadeQuery) appendCascade(fmter schema.Formatter, b []byte) []byte {
if !fmter.HasFeature(feature.TableCascade) {
return b
}
+ if q.cascade {
+ b = append(b, " CASCADE"...)
+ }
if q.restrict {
b = append(b, " RESTRICT"...)
- } else {
- b = append(b, " CASCADE"...)
}
return b
}
diff --git a/vendor/github.com/uptrace/bun/query_column_add.go b/vendor/github.com/uptrace/bun/query_column_add.go
index dff514904..0105fdb38 100644
--- a/vendor/github.com/uptrace/bun/query_column_add.go
+++ b/vendor/github.com/uptrace/bun/query_column_add.go
@@ -15,6 +15,8 @@ type AddColumnQuery struct {
ifNotExists bool
}
+var _ Query = (*AddColumnQuery)(nil)
+
func NewAddColumnQuery(db *DB) *AddColumnQuery {
q := &AddColumnQuery{
baseQuery: baseQuery{
@@ -50,7 +52,7 @@ func (q *AddColumnQuery) TableExpr(query string, args ...interface{}) *AddColumn
}
func (q *AddColumnQuery) ModelTableExpr(query string, args ...interface{}) *AddColumnQuery {
- q.modelTable = schema.SafeQuery(query, args)
+ q.modelTableName = schema.SafeQuery(query, args)
return q
}
diff --git a/vendor/github.com/uptrace/bun/query_column_drop.go b/vendor/github.com/uptrace/bun/query_column_drop.go
index 9fa54610d..cff615f68 100644
--- a/vendor/github.com/uptrace/bun/query_column_drop.go
+++ b/vendor/github.com/uptrace/bun/query_column_drop.go
@@ -13,6 +13,8 @@ type DropColumnQuery struct {
baseQuery
}
+var _ Query = (*DropColumnQuery)(nil)
+
func NewDropColumnQuery(db *DB) *DropColumnQuery {
q := &DropColumnQuery{
baseQuery: baseQuery{
@@ -48,7 +50,7 @@ func (q *DropColumnQuery) TableExpr(query string, args ...interface{}) *DropColu
}
func (q *DropColumnQuery) ModelTableExpr(query string, args ...interface{}) *DropColumnQuery {
- q.modelTable = schema.SafeQuery(query, args)
+ q.modelTableName = schema.SafeQuery(query, args)
return q
}
diff --git a/vendor/github.com/uptrace/bun/query_delete.go b/vendor/github.com/uptrace/bun/query_delete.go
index 6af3dbd2e..83d2dd405 100644
--- a/vendor/github.com/uptrace/bun/query_delete.go
+++ b/vendor/github.com/uptrace/bun/query_delete.go
@@ -15,6 +15,8 @@ type DeleteQuery struct {
returningQuery
}
+var _ Query = (*DeleteQuery)(nil)
+
func NewDeleteQuery(db *DB) *DeleteQuery {
q := &DeleteQuery{
whereBaseQuery: whereBaseQuery{
@@ -60,7 +62,7 @@ func (q *DeleteQuery) TableExpr(query string, args ...interface{}) *DeleteQuery
}
func (q *DeleteQuery) ModelTableExpr(query string, args ...interface{}) *DeleteQuery {
- q.modelTable = schema.SafeQuery(query, args)
+ q.modelTableName = schema.SafeQuery(query, args)
return q
}
@@ -134,6 +136,10 @@ func (q *DeleteQuery) Operation() string {
}
func (q *DeleteQuery) AppendQuery(fmter schema.Formatter, b []byte) (_ []byte, err error) {
+ if q.err != nil {
+ return nil, q.err
+ }
+
fmter = formatterWithModel(fmter, q)
if q.isSoftDelete() {
diff --git a/vendor/github.com/uptrace/bun/query_index_create.go b/vendor/github.com/uptrace/bun/query_index_create.go
index 2b2b1edd7..face759b9 100644
--- a/vendor/github.com/uptrace/bun/query_index_create.go
+++ b/vendor/github.com/uptrace/bun/query_index_create.go
@@ -22,6 +22,8 @@ type CreateIndexQuery struct {
include []schema.QueryWithArgs
}
+var _ Query = (*CreateIndexQuery)(nil)
+
func NewCreateIndexQuery(db *DB) *CreateIndexQuery {
q := &CreateIndexQuery{
whereBaseQuery: whereBaseQuery{
@@ -86,7 +88,7 @@ func (q *CreateIndexQuery) TableExpr(query string, args ...interface{}) *CreateI
}
func (q *CreateIndexQuery) ModelTableExpr(query string, args ...interface{}) *CreateIndexQuery {
- q.modelTable = schema.SafeQuery(query, args)
+ q.modelTableName = schema.SafeQuery(query, args)
return q
}
diff --git a/vendor/github.com/uptrace/bun/query_index_drop.go b/vendor/github.com/uptrace/bun/query_index_drop.go
index 2a641a281..2f5132833 100644
--- a/vendor/github.com/uptrace/bun/query_index_drop.go
+++ b/vendor/github.com/uptrace/bun/query_index_drop.go
@@ -18,6 +18,8 @@ type DropIndexQuery struct {
index schema.QueryWithArgs
}
+var _ Query = (*DropIndexQuery)(nil)
+
func NewDropIndexQuery(db *DB) *DropIndexQuery {
q := &DropIndexQuery{
baseQuery: baseQuery{
@@ -50,6 +52,11 @@ func (q *DropIndexQuery) IfExists() *DropIndexQuery {
return q
}
+func (q *DropIndexQuery) Cascade() *DropIndexQuery {
+ q.cascade = true
+ return q
+}
+
func (q *DropIndexQuery) Restrict() *DropIndexQuery {
q.restrict = true
return q
diff --git a/vendor/github.com/uptrace/bun/query_insert.go b/vendor/github.com/uptrace/bun/query_insert.go
index 240077dd8..6300ab815 100644
--- a/vendor/github.com/uptrace/bun/query_insert.go
+++ b/vendor/github.com/uptrace/bun/query_insert.go
@@ -24,6 +24,8 @@ type InsertQuery struct {
replace bool
}
+var _ Query = (*InsertQuery)(nil)
+
func NewInsertQuery(db *DB) *InsertQuery {
q := &InsertQuery{
whereBaseQuery: whereBaseQuery{
@@ -71,7 +73,7 @@ func (q *InsertQuery) TableExpr(query string, args ...interface{}) *InsertQuery
}
func (q *InsertQuery) ModelTableExpr(query string, args ...interface{}) *InsertQuery {
- q.modelTable = schema.SafeQuery(query, args)
+ q.modelTableName = schema.SafeQuery(query, args)
return q
}
@@ -159,6 +161,10 @@ func (q *InsertQuery) Operation() string {
}
func (q *InsertQuery) AppendQuery(fmter schema.Formatter, b []byte) (_ []byte, err error) {
+ if q.err != nil {
+ return nil, q.err
+ }
+
fmter = formatterWithModel(fmter, q)
b, err = q.appendWith(fmter, b)
diff --git a/vendor/github.com/uptrace/bun/query_select.go b/vendor/github.com/uptrace/bun/query_select.go
index ad4db6670..401bf1acc 100644
--- a/vendor/github.com/uptrace/bun/query_select.go
+++ b/vendor/github.com/uptrace/bun/query_select.go
@@ -34,6 +34,8 @@ type SelectQuery struct {
union []union
}
+var _ Query = (*SelectQuery)(nil)
+
func NewSelectQuery(db *DB) *SelectQuery {
return &SelectQuery{
whereBaseQuery: whereBaseQuery{
@@ -90,7 +92,7 @@ func (q *SelectQuery) TableExpr(query string, args ...interface{}) *SelectQuery
}
func (q *SelectQuery) ModelTableExpr(query string, args ...interface{}) *SelectQuery {
- q.modelTable = schema.SafeQuery(query, args)
+ q.modelTableName = schema.SafeQuery(query, args)
return q
}
@@ -342,9 +344,9 @@ func (q *SelectQuery) selectJoins(ctx context.Context, joins []relationJoin) err
case schema.HasOneRelation, schema.BelongsToRelation:
err = q.selectJoins(ctx, j.JoinModel.getJoins())
case schema.HasManyRelation:
- err = j.selectMany(ctx, q.db.NewSelect())
+ err = j.selectMany(ctx, q.db.NewSelect().Conn(q.conn))
case schema.ManyToManyRelation:
- err = j.selectM2M(ctx, q.db.NewSelect())
+ err = j.selectM2M(ctx, q.db.NewSelect().Conn(q.conn))
default:
panic("not reached")
}
@@ -369,6 +371,10 @@ func (q *SelectQuery) AppendQuery(fmter schema.Formatter, b []byte) (_ []byte, e
func (q *SelectQuery) appendQuery(
fmter schema.Formatter, b []byte, count bool,
) (_ []byte, err error) {
+ if q.err != nil {
+ return nil, q.err
+ }
+
fmter = formatterWithModel(fmter, q)
cteCount := count && (len(q.group) > 0 || q.distinctOn != nil)
@@ -767,7 +773,7 @@ func (q *SelectQuery) Count(ctx context.Context) (int, error) {
}
query := internal.String(queryBytes)
- ctx, event := q.db.beforeQuery(ctx, qq, query, nil, q.model)
+ ctx, event := q.db.beforeQuery(ctx, qq, query, nil, query, q.model)
var num int
err = q.conn.QueryRowContext(ctx, query).Scan(&num)
@@ -778,6 +784,13 @@ func (q *SelectQuery) Count(ctx context.Context) (int, error) {
}
func (q *SelectQuery) ScanAndCount(ctx context.Context, dest ...interface{}) (int, error) {
+ if _, ok := q.conn.(*DB); ok {
+ return q.scanAndCountConc(ctx, dest...)
+ }
+ return q.scanAndCountSeq(ctx, dest...)
+}
+
+func (q *SelectQuery) scanAndCountConc(ctx context.Context, dest ...interface{}) (int, error) {
var count int
var wg sync.WaitGroup
var mu sync.Mutex
@@ -817,6 +830,21 @@ func (q *SelectQuery) ScanAndCount(ctx context.Context, dest ...interface{}) (in
return count, firstErr
}
+func (q *SelectQuery) scanAndCountSeq(ctx context.Context, dest ...interface{}) (int, error) {
+ var firstErr error
+
+ if q.limit >= 0 {
+ firstErr = q.Scan(ctx, dest...)
+ }
+
+ count, err := q.Count(ctx)
+ if err != nil && firstErr == nil {
+ firstErr = err
+ }
+
+ return count, firstErr
+}
+
func (q *SelectQuery) Exists(ctx context.Context) (bool, error) {
if q.err != nil {
return false, q.err
@@ -830,7 +858,7 @@ func (q *SelectQuery) Exists(ctx context.Context) (bool, error) {
}
query := internal.String(queryBytes)
- ctx, event := q.db.beforeQuery(ctx, qq, query, nil, q.model)
+ ctx, event := q.db.beforeQuery(ctx, qq, query, nil, query, q.model)
var exists bool
err = q.conn.QueryRowContext(ctx, query).Scan(&exists)
diff --git a/vendor/github.com/uptrace/bun/query_table_create.go b/vendor/github.com/uptrace/bun/query_table_create.go
index 66bb9c4a1..f2312bc69 100644
--- a/vendor/github.com/uptrace/bun/query_table_create.go
+++ b/vendor/github.com/uptrace/bun/query_table_create.go
@@ -24,6 +24,8 @@ type CreateTableQuery struct {
tablespace schema.QueryWithArgs
}
+var _ Query = (*CreateTableQuery)(nil)
+
func NewCreateTableQuery(db *DB) *CreateTableQuery {
q := &CreateTableQuery{
baseQuery: baseQuery{
@@ -59,7 +61,7 @@ func (q *CreateTableQuery) TableExpr(query string, args ...interface{}) *CreateT
}
func (q *CreateTableQuery) ModelTableExpr(query string, args ...interface{}) *CreateTableQuery {
- q.modelTable = schema.SafeQuery(query, args)
+ q.modelTableName = schema.SafeQuery(query, args)
return q
}
diff --git a/vendor/github.com/uptrace/bun/query_table_drop.go b/vendor/github.com/uptrace/bun/query_table_drop.go
index 8192bd548..bf7ee3031 100644
--- a/vendor/github.com/uptrace/bun/query_table_drop.go
+++ b/vendor/github.com/uptrace/bun/query_table_drop.go
@@ -15,6 +15,8 @@ type DropTableQuery struct {
ifExists bool
}
+var _ Query = (*DropTableQuery)(nil)
+
func NewDropTableQuery(db *DB) *DropTableQuery {
q := &DropTableQuery{
baseQuery: baseQuery{
@@ -50,7 +52,7 @@ func (q *DropTableQuery) TableExpr(query string, args ...interface{}) *DropTable
}
func (q *DropTableQuery) ModelTableExpr(query string, args ...interface{}) *DropTableQuery {
- q.modelTable = schema.SafeQuery(query, args)
+ q.modelTableName = schema.SafeQuery(query, args)
return q
}
@@ -61,6 +63,11 @@ func (q *DropTableQuery) IfExists() *DropTableQuery {
return q
}
+func (q *DropTableQuery) Cascade() *DropTableQuery {
+ q.cascade = true
+ return q
+}
+
func (q *DropTableQuery) Restrict() *DropTableQuery {
q.restrict = true
return q
diff --git a/vendor/github.com/uptrace/bun/query_table_truncate.go b/vendor/github.com/uptrace/bun/query_table_truncate.go
index 765afde92..870c776c6 100644
--- a/vendor/github.com/uptrace/bun/query_table_truncate.go
+++ b/vendor/github.com/uptrace/bun/query_table_truncate.go
@@ -16,6 +16,8 @@ type TruncateTableQuery struct {
continueIdentity bool
}
+var _ Query = (*TruncateTableQuery)(nil)
+
func NewTruncateTableQuery(db *DB) *TruncateTableQuery {
q := &TruncateTableQuery{
baseQuery: baseQuery{
@@ -57,6 +59,11 @@ func (q *TruncateTableQuery) ContinueIdentity() *TruncateTableQuery {
return q
}
+func (q *TruncateTableQuery) Cascade() *TruncateTableQuery {
+ q.cascade = true
+ return q
+}
+
func (q *TruncateTableQuery) Restrict() *TruncateTableQuery {
q.restrict = true
return q
diff --git a/vendor/github.com/uptrace/bun/query_update.go b/vendor/github.com/uptrace/bun/query_update.go
index 5ac394453..f4554e4d3 100644
--- a/vendor/github.com/uptrace/bun/query_update.go
+++ b/vendor/github.com/uptrace/bun/query_update.go
@@ -20,6 +20,8 @@ type UpdateQuery struct {
omitZero bool
}
+var _ Query = (*UpdateQuery)(nil)
+
func NewUpdateQuery(db *DB) *UpdateQuery {
q := &UpdateQuery{
whereBaseQuery: whereBaseQuery{
@@ -67,7 +69,7 @@ func (q *UpdateQuery) TableExpr(query string, args ...interface{}) *UpdateQuery
}
func (q *UpdateQuery) ModelTableExpr(query string, args ...interface{}) *UpdateQuery {
- q.modelTable = schema.SafeQuery(query, args)
+ q.modelTableName = schema.SafeQuery(query, args)
return q
}
@@ -170,6 +172,10 @@ func (q *UpdateQuery) Operation() string {
}
func (q *UpdateQuery) AppendQuery(fmter schema.Formatter, b []byte) (_ []byte, err error) {
+ if q.err != nil {
+ return nil, q.err
+ }
+
fmter = formatterWithModel(fmter, q)
b, err = q.appendWith(fmter, b)
diff --git a/vendor/github.com/uptrace/bun/query_values.go b/vendor/github.com/uptrace/bun/query_values.go
index b6a78476d..9e02c05e6 100644
--- a/vendor/github.com/uptrace/bun/query_values.go
+++ b/vendor/github.com/uptrace/bun/query_values.go
@@ -16,7 +16,10 @@ type ValuesQuery struct {
withOrder bool
}
-var _ schema.NamedArgAppender = (*ValuesQuery)(nil)
+var (
+ _ Query = (*ValuesQuery)(nil)
+ _ schema.NamedArgAppender = (*ValuesQuery)(nil)
+)
func NewValuesQuery(db *DB, model interface{}) *ValuesQuery {
q := &ValuesQuery{
diff --git a/vendor/github.com/uptrace/bun/schema/formatter.go b/vendor/github.com/uptrace/bun/schema/formatter.go
index dd1859acf..1fba1b59e 100644
--- a/vendor/github.com/uptrace/bun/schema/formatter.go
+++ b/vendor/github.com/uptrace/bun/schema/formatter.go
@@ -177,8 +177,6 @@ type NamedArgAppender interface {
AppendNamedArg(fmter Formatter, b []byte, name string) ([]byte, bool)
}
-//------------------------------------------------------------------------------
-
type namedArgList struct {
arg NamedArgAppender
next *namedArgList
@@ -219,13 +217,13 @@ func (a *namedArg) AppendNamedArg(fmter Formatter, b []byte, name string) ([]byt
//------------------------------------------------------------------------------
-var _ NamedArgAppender = (*structArgs)(nil)
-
type structArgs struct {
table *Table
strct reflect.Value
}
+var _ NamedArgAppender = (*structArgs)(nil)
+
func newStructArgs(fmter Formatter, strct interface{}) (*structArgs, bool) {
v := reflect.ValueOf(strct)
if !v.IsValid() {
diff --git a/vendor/github.com/uptrace/bun/schema/table.go b/vendor/github.com/uptrace/bun/schema/table.go
index 823d4c69f..88b8d8e25 100644
--- a/vendor/github.com/uptrace/bun/schema/table.go
+++ b/vendor/github.com/uptrace/bun/schema/table.go
@@ -203,7 +203,7 @@ func (t *Table) fieldByGoName(name string) *Field {
func (t *Table) initFields() {
t.Fields = make([]*Field, 0, t.Type.NumField())
t.FieldMap = make(map[string]*Field, t.Type.NumField())
- t.addFields(t.Type, nil)
+ t.addFields(t.Type, "", nil)
if len(t.PKs) == 0 {
for _, name := range []string{"id", "uuid", "pk_" + t.ModelName} {
@@ -230,7 +230,7 @@ func (t *Table) initFields() {
}
}
-func (t *Table) addFields(typ reflect.Type, baseIndex []int) {
+func (t *Table) addFields(typ reflect.Type, prefix string, index []int) {
for i := 0; i < typ.NumField(); i++ {
f := typ.Field(i)
unexported := f.PkgPath != ""
@@ -242,10 +242,6 @@ func (t *Table) addFields(typ reflect.Type, baseIndex []int) {
continue
}
- // Make a copy so the slice is not shared between fields.
- index := make([]int, len(baseIndex))
- copy(index, baseIndex)
-
if f.Anonymous {
if f.Name == "BaseModel" && f.Type == baseModelType {
if len(index) == 0 {
@@ -258,7 +254,7 @@ func (t *Table) addFields(typ reflect.Type, baseIndex []int) {
if fieldType.Kind() != reflect.Struct {
continue
}
- t.addFields(fieldType, append(index, f.Index...))
+ t.addFields(fieldType, "", withIndex(index, f.Index))
tag := tagparser.Parse(f.Tag.Get("bun"))
if _, inherit := tag.Options["inherit"]; inherit {
@@ -274,7 +270,7 @@ func (t *Table) addFields(typ reflect.Type, baseIndex []int) {
continue
}
- if field := t.newField(f, index); field != nil {
+ if field := t.newField(f, prefix, index); field != nil {
t.addField(field)
}
}
@@ -315,10 +311,20 @@ func (t *Table) processBaseModelField(f reflect.StructField) {
}
//nolint
-func (t *Table) newField(f reflect.StructField, index []int) *Field {
- sqlName := internal.Underscore(f.Name)
+func (t *Table) newField(f reflect.StructField, prefix string, index []int) *Field {
tag := tagparser.Parse(f.Tag.Get("bun"))
+ if prefix, ok := tag.Option("embed"); ok {
+ fieldType := indirectType(f.Type)
+ if fieldType.Kind() != reflect.Struct {
+ panic(fmt.Errorf("bun: embed %s.%s: got %s, wanted reflect.Struct",
+ t.TypeName, f.Name, fieldType.Kind()))
+ }
+ t.addFields(fieldType, prefix, withIndex(index, f.Index))
+ return nil
+ }
+
+ sqlName := internal.Underscore(f.Name)
if tag.Name != "" && tag.Name != sqlName {
if isKnownFieldOption(tag.Name) {
internal.Warn.Printf(
@@ -328,10 +334,10 @@ func (t *Table) newField(f reflect.StructField, index []int) *Field {
}
sqlName = tag.Name
}
-
if s, ok := tag.Option("column"); ok {
sqlName = s
}
+ sqlName = prefix + sqlName
for name := range tag.Options {
if !isKnownFieldOption(name) {
@@ -339,7 +345,7 @@ func (t *Table) newField(f reflect.StructField, index []int) *Field {
}
}
- index = append(index, f.Index...)
+ index = withIndex(index, f.Index)
if field := t.fieldWithLock(sqlName); field != nil {
if indexEqual(field.Index, index) {
return field
@@ -795,7 +801,7 @@ func (t *Table) inlineFields(field *Field, seen map[reflect.Type]struct{}) {
f.GoName = field.GoName + "_" + f.GoName
f.Name = field.Name + "__" + f.Name
f.SQLName = t.quoteIdent(f.Name)
- f.Index = appendNew(field.Index, f.Index...)
+ f.Index = withIndex(field.Index, f.Index)
t.fieldsMapMu.Lock()
if _, ok := t.FieldMap[f.Name]; !ok {
@@ -834,7 +840,7 @@ func (t *Table) AppendNamedArg(
fmter Formatter, b []byte, name string, strct reflect.Value,
) ([]byte, bool) {
if field, ok := t.FieldMap[name]; ok {
- return fmter.appendArg(b, field.Value(strct).Interface()), true
+ return field.AppendValue(fmter, b, strct), true
}
return b, false
}
@@ -853,13 +859,6 @@ func (t *Table) quoteIdent(s string) Safe {
return Safe(NewFormatter(t.dialect).AppendIdent(nil, s))
}
-func appendNew(dst []int, src ...int) []int {
- cp := make([]int, len(dst)+len(src))
- copy(cp, dst)
- copy(cp[len(dst):], src)
- return cp
-}
-
func isKnownTableOption(name string) bool {
switch name {
case "table", "alias", "select":
@@ -991,3 +990,10 @@ func softDeleteFieldUpdaterFallback(field *Field) func(fv reflect.Value, tm time
return field.ScanWithCheck(fv, tm)
}
}
+
+func withIndex(a, b []int) []int {
+ dest := make([]int, 0, len(a)+len(b))
+ dest = append(dest, a...)
+ dest = append(dest, b...)
+ return dest
+}
diff --git a/vendor/github.com/uptrace/bun/version.go b/vendor/github.com/uptrace/bun/version.go
index a4704b31c..919d06938 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.19"
+ return "1.0.20"
}