MCPcopy Index your code
hub / github.com/go-dev-frame/sponge / getModelStructCode

Function getModelStructCode

pkg/sql2code/parser/parser.go:681–804  ·  view source on GitHub ↗

nolint

(data tmplData, importPaths []string, isEmbed bool, jsonNamedType int)

Source from the content-addressed store, hash-verified

679
680// nolint
681func 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" {

Callers 1

makeCodeFunction · 0.85

Calls 6

isIgnoreFieldsFunction · 0.85
getTableColumnsCodeFunction · 0.85
isCommonStyleMethod · 0.80
ErrorfMethod · 0.80
ExecuteMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected