Skip to content

Commit

Permalink
fix: restore explicit column: name override
Browse files Browse the repository at this point in the history
Accidentally removed in commit 9052fc4.
  • Loading branch information
shiar committed May 3, 2024
1 parent b005dc2 commit bbe85d7
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 0 deletions.
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

0 comments on commit bbe85d7

Please sign in to comment.