Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: restore explicit column: name override #984

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions internal/dbtest/query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1545,6 +1545,17 @@ func TestQuery(t *testing.T) {
return db.NewInsert().Model(new(Model))
},
},
{
id: 167,
query: func(db *bun.DB) schema.QueryAppender {
// specified option names
type Model struct {
bun.BaseModel `bun:"table:table"`
IsDefault bool `bun:"column:default"`
}
return db.NewInsert().Model(new(Model))
},
},
}

timeRE := regexp.MustCompile(`'2\d{3}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(\.\d+)?(\+\d{2}:\d{2})?'`)
Expand Down
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mariadb-167
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO `table` (`default`) VALUES (FALSE)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mssql2019-167
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO "table" ("default") VALUES (0)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql5-167
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO `table` (`default`) VALUES (FALSE)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-mysql8-167
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO `table` (`default`) VALUES (FALSE)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pg-167
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO "table" ("default") VALUES (FALSE)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-pgx-167
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO "table" ("default") VALUES (FALSE)
1 change: 1 addition & 0 deletions internal/dbtest/testdata/snapshots/TestQuery-sqlite-167
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO "table" ("default") VALUES (FALSE)
4 changes: 4 additions & 0 deletions schema/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,10 @@ func (t *Table) newField(sf reflect.StructField, tag tagparser.Tag) *Field {
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, sf.Name, name)
Expand Down
Loading