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

Function convertToSQLBySqliteFields

pkg/sql2code/parser/sqlite.go:74–95  ·  view source on GitHub ↗
(tableName string, fields SqliteFields)

Source from the content-addressed store, hash-verified

72}
73
74func convertToSQLBySqliteFields(tableName string, fields SqliteFields) string {
75 if len(fields) == 0 {
76 return ""
77 }
78
79 fieldStr := ""
80 for _, field := range fields {
81 notnullStr := "not null"
82 if field.Notnull == 0 {
83 notnullStr = "null"
84 }
85 fieldStr += fmt.Sprintf(" `%s` %s %s comment '%s',\n", field.Name, field.getMysqlType(), notnullStr, "")
86 }
87
88 primaryField := fields.getPrimaryField()
89 if primaryField != nil {
90 fieldStr += fmt.Sprintf(" PRIMARY KEY (`%s`)\n", primaryField.Name)
91 } else {
92 fieldStr = strings.TrimSuffix(fieldStr, ",\n")
93 }
94 return fmt.Sprintf("CREATE TABLE `%s` (\n%s\n);", tableName, fieldStr)
95}

Callers 1

GetSqliteTableInfoFunction · 0.85

Calls 2

getMysqlTypeMethod · 0.45
getPrimaryFieldMethod · 0.45

Tested by

no test coverage detected