nolint
(data tmplData, importPaths []string, isEmbed bool, jsonNamedType int)
| 679 | |
| 680 | // nolint |
| 681 | func getModelStructCode(data tmplData, importPaths []string, isEmbed bool, jsonNamedType int) (string, []string, error) { |
| 682 | // filter to ignore field fields |
| 683 | var newFields = []tmplField{} |
| 684 | var newImportPaths = []string{} |
| 685 | if isEmbed { |
| 686 | newFields = append(newFields, tmplField{ |
| 687 | Name: __mysqlModel__, |
| 688 | ColName: __mysqlModel__, |
| 689 | GoType: __type__, |
| 690 | Tag: `gorm:"embedded"`, |
| 691 | Comment: "embed id and time\n", |
| 692 | }) |
| 693 | |
| 694 | isHaveTimeType := false |
| 695 | for _, field := range data.Fields { |
| 696 | if isIgnoreFields(field.ColName) { |
| 697 | continue |
| 698 | } |
| 699 | switch field.DBDriver { |
| 700 | case DBDriverMysql, DBDriverTidb, DBDriverPostgresql: |
| 701 | if strings.Contains(field.GoType, "time.Time") { |
| 702 | field.GoType = "*time.Time" |
| 703 | } |
| 704 | if field.rewriterField != nil { |
| 705 | switch field.rewriterField.goType { |
| 706 | case jsonTypeName, decimalTypeName, boolTypeName, boolTypeTinyName: |
| 707 | field.GoType = "*" + field.rewriterField.goType |
| 708 | importPaths = append(importPaths, field.rewriterField.path) |
| 709 | } |
| 710 | } |
| 711 | } |
| 712 | newFields = append(newFields, field) |
| 713 | if strings.Contains(field.GoType, "time.Time") { |
| 714 | isHaveTimeType = true |
| 715 | } |
| 716 | } |
| 717 | data.Fields = newFields |
| 718 | |
| 719 | // filter time package name |
| 720 | if isHaveTimeType { |
| 721 | newImportPaths = importPaths |
| 722 | } else { |
| 723 | for _, path := range importPaths { |
| 724 | if path == "time" { //nolint |
| 725 | continue |
| 726 | } |
| 727 | newImportPaths = append(newImportPaths, path) |
| 728 | } |
| 729 | } |
| 730 | newImportPaths = append(newImportPaths, "github.com/go-dev-frame/sponge/pkg/sgorm") |
| 731 | } else { |
| 732 | for _, field := range data.Fields { |
| 733 | if strings.Contains(field.GoType, "time.Time") { |
| 734 | field.GoType = "*time.Time" |
| 735 | } |
| 736 | switch field.DBDriver { |
| 737 | case DBDriverMongodb: |
| 738 | if field.Name == "ID" { |
no test coverage detected