perf(schema): avoid redundant strings.ToLower call

This commit is contained in:
1911860538 2025-05-23 23:01:14 +08:00
parent 8e7ab46c1b
commit 411946278a
2 changed files with 5 additions and 3 deletions

View File

@ -318,9 +318,10 @@ func (schema *Schema) ParseField(fieldStruct reflect.StructField) *Field {
}
if val, ok := field.TagSettings["TYPE"]; ok {
switch DataType(strings.ToLower(val)) {
lowerVal := DataType(strings.ToLower(val))
switch lowerVal {
case Bool, Int, Uint, Float, String, Time, Bytes:
field.DataType = DataType(strings.ToLower(val))
field.DataType = lowerVal
default:
field.DataType = DataType(val)
}

View File

@ -763,8 +763,9 @@ func (rel *Relationship) ToQueryConditions(ctx context.Context, reflectValue ref
}
func copyableDataType(str DataType) bool {
lowerStr := strings.ToLower(string(str))
for _, s := range []string{"auto_increment", "primary key"} {
if strings.Contains(strings.ToLower(string(str)), s) {
if strings.Contains(lowerStr, s) {
return false
}
}