Skip to content

Commit

Permalink
🩹 修复 GORM 方言数据类型自增列判断条件
Browse files Browse the repository at this point in the history
Signed-off-by: liutianqi <[email protected]>
  • Loading branch information
iTanken committed Dec 27, 2023
1 parent 70ac18d commit 19e0793
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"gorm.io/gorm/logger"
"gorm.io/gorm/migrator"
"gorm.io/gorm/schema"
"gorm.io/gorm/utils"
)

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

var sqlType string

switch field.DataType {
case schema.Bool:
sqlType = "NUMBER(1)"
case schema.Int, schema.Uint, schema.Float:
case schema.Int, schema.Uint:
sqlType = "INTEGER"

switch {
case field.DataType == schema.Float:
sqlType = "FLOAT"
case field.Size > 0 && field.Size <= 8:
if field.Size > 0 && field.Size <= 8 {
sqlType = "SMALLINT"
}

if val, ok := field.TagSettings["AUTOINCREMENT"]; ok && utils.CheckTruth(val) {
if field.AutoIncrement {
sqlType += " GENERATED BY DEFAULT AS IDENTITY"
}
case schema.Float:
sqlType = "FLOAT"
case schema.String, "VARCHAR2":
size := field.Size
defaultSize := d.DefaultStringSize
Expand All @@ -387,10 +383,8 @@ func (d Dialector) DataTypeOf(field *schema.Field) string {
} else {
sqlType = "CLOB"
}

case schema.Time:
sqlType = "TIMESTAMP WITH TIME ZONE"

case schema.Bytes:
sqlType = "BLOB"
default:
Expand All @@ -403,7 +397,6 @@ func (d Dialector) DataTypeOf(field *schema.Field) string {
if sqlType == "" {
panic(fmt.Sprintf("invalid sql type %s (%s) for oracle", field.FieldType.Name(), field.FieldType.String()))
}

}

return sqlType
Expand Down

0 comments on commit 19e0793

Please sign in to comment.