mirror of
https://github.com/superseriousbusiness/gotosocial.git
synced 2025-11-02 05:22:25 -06:00
[feature] Clean up/uncache remote media (#407)
* Add whereNotEmptyAndNotNull * Add GetRemoteOlderThanDays * Add GetRemoteOlderThanDays * Add PruneRemote to Manager interface * Start implementing PruneRemote * add new attachment + status to tests * fix up and test GetRemoteOlderThan * fix bad import * PruneRemote: return number pruned * add Cached column to mediaattachment * update + test pruneRemote * update mediaTest * use Cached column * upstep bun to latest version * embed structs in mediaAttachment * migrate mediaAttachment to new format * don't default cached to true * select only remote media * update db dependencies * step bun back to last working version * update pruneRemote to use Cached field * fix storage path of test attachments * add recache logic to manager * fix trimmed aspect ratio * test prune and recache * return errwithcode * tidy up different paths for emoji vs attachment * fix incorrect thumbnail type being stored * expose TransportController to media processor * implement tee-ing recached content * add thoughts of dog to test fedi attachments * test get remote files * add comment on PruneRemote * add postData cleanup to recache * test thumbnail fetching * add incredible diagram * go mod tidy * buffer pipes for recache streaming * test for client stops reading after 1kb * add media-remote-cache-days to config * add cron package * wrap logrus so it's available to cron * start and stop cron jobs gracefully
This commit is contained in:
parent
100f1280a6
commit
07727753b9
424 changed files with 637100 additions and 176498 deletions
23
vendor/github.com/uptrace/bun/CHANGELOG.md
generated
vendored
23
vendor/github.com/uptrace/bun/CHANGELOG.md
generated
vendored
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
|||
141
vendor/github.com/uptrace/bun/README.md
generated
vendored
141
vendor/github.com/uptrace/bun/README.md
generated
vendored
|
|
@ -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
|
||||
|
|
|
|||
62
vendor/github.com/uptrace/bun/db.go
generated
vendored
62
vendor/github.com/uptrace/bun/db.go
generated
vendored
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
7
vendor/github.com/uptrace/bun/hook.go
generated
vendored
7
vendor/github.com/uptrace/bun/hook.go
generated
vendored
|
|
@ -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(),
|
||||
|
|
|
|||
55
vendor/github.com/uptrace/bun/migrate/migrator.go
generated
vendored
55
vendor/github.com/uptrace/bun/migrate/migrator.go
generated
vendored
|
|
@ -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).
|
||||
|
|
|
|||
2
vendor/github.com/uptrace/bun/package.json
generated
vendored
2
vendor/github.com/uptrace/bun/package.json
generated
vendored
|
|
@ -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>",
|
||||
|
|
|
|||
101
vendor/github.com/uptrace/bun/query_base.go
generated
vendored
101
vendor/github.com/uptrace/bun/query_base.go
generated
vendored
|
|
@ -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 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)
|
||||
return
|
||||
}
|
||||
|
||||
q.whereFields = fields
|
||||
if cols == nil {
|
||||
if err := q.table.CheckPKs(); err != nil {
|
||||
q.setErr(err)
|
||||
return
|
||||
}
|
||||
q.whereFields = q.table.PKs
|
||||
return
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
|
|
|||
4
vendor/github.com/uptrace/bun/query_column_add.go
generated
vendored
4
vendor/github.com/uptrace/bun/query_column_add.go
generated
vendored
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
4
vendor/github.com/uptrace/bun/query_column_drop.go
generated
vendored
4
vendor/github.com/uptrace/bun/query_column_drop.go
generated
vendored
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
8
vendor/github.com/uptrace/bun/query_delete.go
generated
vendored
8
vendor/github.com/uptrace/bun/query_delete.go
generated
vendored
|
|
@ -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() {
|
||||
|
|
|
|||
4
vendor/github.com/uptrace/bun/query_index_create.go
generated
vendored
4
vendor/github.com/uptrace/bun/query_index_create.go
generated
vendored
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
7
vendor/github.com/uptrace/bun/query_index_drop.go
generated
vendored
7
vendor/github.com/uptrace/bun/query_index_drop.go
generated
vendored
|
|
@ -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
|
||||
|
|
|
|||
8
vendor/github.com/uptrace/bun/query_insert.go
generated
vendored
8
vendor/github.com/uptrace/bun/query_insert.go
generated
vendored
|
|
@ -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)
|
||||
|
|
|
|||
38
vendor/github.com/uptrace/bun/query_select.go
generated
vendored
38
vendor/github.com/uptrace/bun/query_select.go
generated
vendored
|
|
@ -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)
|
||||
|
|
|
|||
4
vendor/github.com/uptrace/bun/query_table_create.go
generated
vendored
4
vendor/github.com/uptrace/bun/query_table_create.go
generated
vendored
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
9
vendor/github.com/uptrace/bun/query_table_drop.go
generated
vendored
9
vendor/github.com/uptrace/bun/query_table_drop.go
generated
vendored
|
|
@ -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
|
||||
|
|
|
|||
7
vendor/github.com/uptrace/bun/query_table_truncate.go
generated
vendored
7
vendor/github.com/uptrace/bun/query_table_truncate.go
generated
vendored
|
|
@ -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
|
||||
|
|
|
|||
8
vendor/github.com/uptrace/bun/query_update.go
generated
vendored
8
vendor/github.com/uptrace/bun/query_update.go
generated
vendored
|
|
@ -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)
|
||||
|
|
|
|||
5
vendor/github.com/uptrace/bun/query_values.go
generated
vendored
5
vendor/github.com/uptrace/bun/query_values.go
generated
vendored
|
|
@ -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{
|
||||
|
|
|
|||
6
vendor/github.com/uptrace/bun/schema/formatter.go
generated
vendored
6
vendor/github.com/uptrace/bun/schema/formatter.go
generated
vendored
|
|
@ -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() {
|
||||
|
|
|
|||
48
vendor/github.com/uptrace/bun/schema/table.go
generated
vendored
48
vendor/github.com/uptrace/bun/schema/table.go
generated
vendored
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
2
vendor/github.com/uptrace/bun/version.go
generated
vendored
2
vendor/github.com/uptrace/bun/version.go
generated
vendored
|
|
@ -2,5 +2,5 @@ package bun
|
|||
|
||||
// Version is the current release version.
|
||||
func Version() string {
|
||||
return "1.0.19"
|
||||
return "1.0.20"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue