fix: enhance condition handling for SQL drivers by adding nil checks for time.Time

This commit is contained in:
Eric-Guo
2025-08-09 00:04:21 +08:00
parent 77e1490480
commit ff8ba9ced7

View File

@@ -211,7 +211,7 @@ func (t tmplField) ConditionZero() string {
case "string", "sql.NullString": //nolint
return ` != ""`
case "time.Time", "*time.Time", "sql.NullTime": //nolint
return `.IsZero() == false`
return ` != nil && table.` + t.Name + `.IsZero() == false`
case "[]byte", "[]string", "[]int", "interface{}": //nolint
return ` != nil` //nolint
case "bool": //nolint
@@ -681,6 +681,9 @@ func getModelStructCode(data tmplData, importPaths []string, isEmbed bool, jsonN
}
switch field.DBDriver {
case DBDriverMysql, DBDriverTidb, DBDriverPostgresql:
if strings.Contains(field.GoType, "time.Time") {
field.GoType = "*time.Time"
}
if field.rewriterField != nil {
switch field.rewriterField.goType {
//case jsonTypeName, decimalTypeName: