(tableName string, fields SqliteFields)
| 72 | } |
| 73 | |
| 74 | func 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 | } |
no test coverage detected