diff options
author | 2021-12-12 15:47:51 +0100 | |
---|---|---|
committer | 2021-12-12 15:47:51 +0100 | |
commit | 67ac8db190eb82a7758746fb021fa3014f4241b7 (patch) | |
tree | 4a4124ad8f0ee9ec8858b109dd0bcc2e567fc144 /vendor/github.com/uptrace | |
parent | upstep dependencies (#339) (diff) | |
download | gotosocial-67ac8db190eb82a7758746fb021fa3014f4241b7.tar.xz |
Upstep Go dependencies (#340)
* Upstep Go dependencies
* tiny linter fix
* Tidy
Diffstat (limited to 'vendor/github.com/uptrace')
-rw-r--r-- | vendor/github.com/uptrace/bun/CHANGELOG.md | 9 | ||||
-rw-r--r-- | vendor/github.com/uptrace/bun/README.md | 149 | ||||
-rw-r--r-- | vendor/github.com/uptrace/bun/db.go | 9 | ||||
-rw-r--r-- | vendor/github.com/uptrace/bun/package.json | 2 | ||||
-rw-r--r-- | vendor/github.com/uptrace/bun/query_update.go | 11 | ||||
-rw-r--r-- | vendor/github.com/uptrace/bun/schema/table.go | 23 | ||||
-rw-r--r-- | vendor/github.com/uptrace/bun/version.go | 2 |
7 files changed, 48 insertions, 157 deletions
diff --git a/vendor/github.com/uptrace/bun/CHANGELOG.md b/vendor/github.com/uptrace/bun/CHANGELOG.md index afffdb2eb..2b1082c5a 100644 --- a/vendor/github.com/uptrace/bun/CHANGELOG.md +++ b/vendor/github.com/uptrace/bun/CHANGELOG.md @@ -1,3 +1,12 @@ +## [1.0.19](https://github.com/uptrace/bun/compare/v1.0.18...v1.0.19) (2021-11-30) + + +### Features + +* add support for column:name to specify column name ([e37b460](https://github.com/uptrace/bun/commit/e37b4602823babc8221970e086cfed90c6ad4cf4)) + + + ## [1.0.18](https://github.com/uptrace/bun/compare/v1.0.17...v1.0.18) (2021-11-24) diff --git a/vendor/github.com/uptrace/bun/README.md b/vendor/github.com/uptrace/bun/README.md index 0c27b9a37..2eeff3bc1 100644 --- a/vendor/github.com/uptrace/bun/README.md +++ b/vendor/github.com/uptrace/bun/README.md @@ -29,10 +29,10 @@ Main features are: Resources: -- [Discussions](https://github.com/uptrace/bun/discussions). -- [Newsletter](https://blog.uptrace.dev/pages/newsletter.html) to get latest updates. +- [**Get started**](https://bun.uptrace.dev/guide/getting-started.html) - [Examples](https://github.com/uptrace/bun/tree/master/example) -- [Documentation](https://bun.uptrace.dev/) +- [Discussions](https://github.com/uptrace/bun/discussions) +- [Newsletter](https://blog.uptrace.dev/pages/newsletter.html) to get latest updates. - [Reference](https://pkg.go.dev/github.com/uptrace/bun) - [Starter kit](https://github.com/go-bun/bun-starter-kit) @@ -156,147 +156,8 @@ go get github.com/uptrace/bun You also need to install a database/sql driver and the corresponding Bun [dialect](https://bun.uptrace.dev/guide/drivers.html). -## Quickstart - -First you need to create a `sql.DB`. Here we are using the -[sqliteshim](https://pkg.go.dev/github.com/uptrace/bun/driver/sqliteshim) driver which chooses -between [modernc.org/sqlite](https://modernc.org/sqlite/) and -[mattn/go-sqlite3](https://github.com/mattn/go-sqlite3) depending on your platform. - -```go -import "github.com/uptrace/bun/driver/sqliteshim" - -sqldb, err := sql.Open(sqliteshim.ShimName, "file::memory:?cache=shared") -if err != nil { - panic(err) -} -``` - -And then create a `bun.DB` on top of it using the corresponding SQLite -[dialect](https://bun.uptrace.dev/guide/drivers.html) that comes with Bun: - -```go -import ( - "github.com/uptrace/bun" - "github.com/uptrace/bun/dialect/sqlitedialect" -) - -db := bun.NewDB(sqldb, sqlitedialect.New()) -``` - -Now you are ready to issue some queries: - -```go -type User struct { - ID int64 - Name string -} - -user := new(User) -err := db.NewSelect(). - Model(user). - Where("name != ?", ""). - OrderExpr("id ASC"). - Limit(1). - Scan(ctx) -``` - -## Basic example - -To provide initial data for our [example](/example/basic/), we will use Bun -[fixtures](https://bun.uptrace.dev/guide/fixtures.html): - -```go -import "github.com/uptrace/bun/dbfixture" - -// Register models for the fixture. -db.RegisterModel((*User)(nil), (*Story)(nil)) - -// WithRecreateTables tells Bun to drop existing tables and create new ones. -fixture := dbfixture.New(db, dbfixture.WithRecreateTables()) - -// Load fixture.yml which contains data for User and Story models. -if err := fixture.Load(ctx, os.DirFS("."), "fixture.yml"); err != nil { - panic(err) -} -``` - -The `fixture.yml` looks like this: - -```yaml -- model: User - rows: - - _id: admin - name: admin - emails: ['admin1@admin', 'admin2@admin'] - - _id: root - name: root - emails: ['root1@root', 'root2@root'] - -- model: Story - rows: - - title: Cool story - author_id: '{{ $.User.admin.ID }}' -``` - -To select all users: - -```go -users := make([]User, 0) -if err := db.NewSelect().Model(&users).OrderExpr("id ASC").Scan(ctx); err != nil { - panic(err) -} -``` - -To select a single user by id: - -```go -user1 := new(User) -if err := db.NewSelect().Model(user1).Where("id = ?", 1).Scan(ctx); err != nil { - panic(err) -} -``` - -To select a story and the associated author in a single query: - -```go -story := new(Story) -if err := db.NewSelect(). - Model(story). - Relation("Author"). - Limit(1). - Scan(ctx); err != nil { - panic(err) -} -``` - -To select a user into a map: - -```go -m := make(map[string]interface{}) -if err := db.NewSelect(). - Model((*User)(nil)). - Limit(1). - Scan(ctx, &m); err != nil { - panic(err) -} -``` - -To select all users scanning each column into a separate slice: - -```go -var ids []int64 -var names []string -if err := db.NewSelect(). - ColumnExpr("id, name"). - Model((*User)(nil)). - OrderExpr("id ASC"). - Scan(ctx, &ids, &names); err != nil { - panic(err) -} -``` - -For more details, please consult [docs](https://bun.uptrace.dev/) and check [examples](example). +See [**Getting started**](https://bun.uptrace.dev/guide/getting-started.html) guide and check +[examples](example). ## Contributors diff --git a/vendor/github.com/uptrace/bun/db.go b/vendor/github.com/uptrace/bun/db.go index c32474cef..a83b07d35 100644 --- a/vendor/github.com/uptrace/bun/db.go +++ b/vendor/github.com/uptrace/bun/db.go @@ -203,6 +203,15 @@ func (db *DB) Formatter() schema.Formatter { return db.fmter } +// UpdateFQN returns a fully qualified column name. For MySQL, it returns the column name with +// the table alias. For other RDBMS, it returns just the column name. +func (db *DB) UpdateFQN(alias, column string) Ident { + if db.HasFeature(feature.UpdateMultiTable) { + return Ident(alias + "." + column) + } + return Ident(column) +} + // HasFeature uses feature package to report whether the underlying DBMS supports this feature. func (db *DB) HasFeature(feat feature.Feature) bool { return db.fmter.HasFeature(feat) diff --git a/vendor/github.com/uptrace/bun/package.json b/vendor/github.com/uptrace/bun/package.json index bb01b6cd1..50f48e152 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.18", + "version": "1.0.19", "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_update.go b/vendor/github.com/uptrace/bun/query_update.go index 23c722f56..5ac394453 100644 --- a/vendor/github.com/uptrace/bun/query_update.go +++ b/vendor/github.com/uptrace/bun/query_update.go @@ -452,9 +452,12 @@ func (q *UpdateQuery) afterUpdateHook(ctx context.Context) error { // FQN returns a fully qualified column name. For MySQL, it returns the column name with // the table alias. For other RDBMS, it returns just the column name. -func (q *UpdateQuery) FQN(name string) Ident { - if q.db.fmter.HasFeature(feature.UpdateMultiTable) { - return Ident(q.table.Alias + "." + name) +func (q *UpdateQuery) FQN(column string) Ident { + if q.table == nil { + panic("UpdateQuery.FQN requires a model") + } + if q.db.HasFeature(feature.UpdateMultiTable) { + return Ident(q.table.Alias + "." + column) } - return Ident(name) + return Ident(column) } diff --git a/vendor/github.com/uptrace/bun/schema/table.go b/vendor/github.com/uptrace/bun/schema/table.go index 642881087..823d4c69f 100644 --- a/vendor/github.com/uptrace/bun/schema/table.go +++ b/vendor/github.com/uptrace/bun/schema/table.go @@ -285,8 +285,8 @@ func (t *Table) processBaseModelField(f reflect.StructField) { if isKnownTableOption(tag.Name) { internal.Warn.Printf( - "%s.%s tag name %q is also an option name; is it a mistake?", - t.TypeName, f.Name, tag.Name, + "%s.%s tag name %q is also an option name, is it a mistake? Try table:%s.", + t.TypeName, f.Name, tag.Name, tag.Name, ) } @@ -300,6 +300,10 @@ func (t *Table) processBaseModelField(f reflect.StructField) { t.setName(tag.Name) } + if s, ok := tag.Option("table"); ok { + t.setName(s) + } + if s, ok := tag.Option("select"); ok { t.SQLNameForSelects = t.quoteTableName(s) } @@ -312,19 +316,23 @@ func (t *Table) processBaseModelField(f reflect.StructField) { //nolint func (t *Table) newField(f reflect.StructField, index []int) *Field { + sqlName := internal.Underscore(f.Name) tag := tagparser.Parse(f.Tag.Get("bun")) - sqlName := internal.Underscore(f.Name) if tag.Name != "" && tag.Name != sqlName { if isKnownFieldOption(tag.Name) { internal.Warn.Printf( - "%s.%s tag name %q is also an option name; is it a mistake?", - t.TypeName, f.Name, tag.Name, + "%s.%s tag name %q is also an option name, is it a mistake? Try column:%s.", + t.TypeName, f.Name, tag.Name, tag.Name, ) } sqlName = tag.Name } + if s, ok := tag.Option("column"); ok { + sqlName = s + } + for name := range tag.Options { if !isKnownFieldOption(name) { internal.Warn.Printf("%s.%s has unknown tag option: %q", t.TypeName, f.Name, name) @@ -854,7 +862,7 @@ func appendNew(dst []int, src ...int) []int { func isKnownTableOption(name string) bool { switch name { - case "alias", "select": + case "table", "alias", "select": return true } return false @@ -862,7 +870,8 @@ func isKnownTableOption(name string) bool { func isKnownFieldOption(name string) bool { switch name { - case "alias", + case "column", + "alias", "type", "array", "hstore", diff --git a/vendor/github.com/uptrace/bun/version.go b/vendor/github.com/uptrace/bun/version.go index d2ebe5240..a4704b31c 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.18" + return "1.0.19" } |