Skip to content

Commit 19e0793

Browse files
committed
🩹 修复 GORM 方言数据类型自增列判断条件
Signed-off-by: liutianqi <[email protected]>
1 parent 70ac18d commit 19e0793

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

oracle.go

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"gorm.io/gorm/logger"
1919
"gorm.io/gorm/migrator"
2020
"gorm.io/gorm/schema"
21-
"gorm.io/gorm/utils"
2221
)
2322

2423
type Config struct {
@@ -349,23 +348,20 @@ func (d Dialector) DataTypeOf(field *schema.Field) string {
349348
delete(field.TagSettings, "RESTRICT")
350349

351350
var sqlType string
352-
353351
switch field.DataType {
354352
case schema.Bool:
355353
sqlType = "NUMBER(1)"
356-
case schema.Int, schema.Uint, schema.Float:
354+
case schema.Int, schema.Uint:
357355
sqlType = "INTEGER"
358-
359-
switch {
360-
case field.DataType == schema.Float:
361-
sqlType = "FLOAT"
362-
case field.Size > 0 && field.Size <= 8:
356+
if field.Size > 0 && field.Size <= 8 {
363357
sqlType = "SMALLINT"
364358
}
365359

366-
if val, ok := field.TagSettings["AUTOINCREMENT"]; ok && utils.CheckTruth(val) {
360+
if field.AutoIncrement {
367361
sqlType += " GENERATED BY DEFAULT AS IDENTITY"
368362
}
363+
case schema.Float:
364+
sqlType = "FLOAT"
369365
case schema.String, "VARCHAR2":
370366
size := field.Size
371367
defaultSize := d.DefaultStringSize
@@ -387,10 +383,8 @@ func (d Dialector) DataTypeOf(field *schema.Field) string {
387383
} else {
388384
sqlType = "CLOB"
389385
}
390-
391386
case schema.Time:
392387
sqlType = "TIMESTAMP WITH TIME ZONE"
393-
394388
case schema.Bytes:
395389
sqlType = "BLOB"
396390
default:
@@ -403,7 +397,6 @@ func (d Dialector) DataTypeOf(field *schema.Field) string {
403397
if sqlType == "" {
404398
panic(fmt.Sprintf("invalid sql type %s (%s) for oracle", field.FieldType.Name(), field.FieldType.String()))
405399
}
406-
407400
}
408401

409402
return sqlType

0 commit comments

Comments
 (0)