Upstep Go dependencies (#340)

* Upstep Go dependencies

* tiny linter fix

* Tidy
This commit is contained in:
tobi
2021-12-12 15:47:51 +01:00
committed by GitHub
parent 5506a5ecbe
commit 67ac8db190
160 changed files with 248601 additions and 232400 deletions

View File

@ -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",