diff --git a/database/gdb/gdb_model_create_table.go b/database/gdb/gdb_model_create_table.go index d77da5f93fa..f8b91e0b706 100644 --- a/database/gdb/gdb_model_create_table.go +++ b/database/gdb/gdb_model_create_table.go @@ -193,7 +193,7 @@ var autoIncrementMapping = map[string]string{ "oracle": "GENERATED BY DEFAULT AS IDENTITY", "dm": "AUTO_INCREMENT", "duckdb": "", // 内存库,不支持传统意义上的自增 - "pgsql": "SERIAL", //最新版本psql 使用BIGSERIAL + "pgsql": "SERIAL", // 最新版本pgsql 使用BIGSERIAL "clickhouse": "AUTO_INCREMENT", } @@ -216,13 +216,13 @@ func (m *Model) AutoMigrate(ctx context.Context, model interface{}) error { // 获取数据库类型 dbType := m.db.GetCore().config.Type - //获取字段类型映射 + // 获取字段类型映射 typeMap, ok := typeMapping[dbType] if !ok { return fmt.Errorf("unsupported database type: %s", dbType) } - //获取自增字段语法映射 + // 获取自增字段语法映射 autoIncrement, ok := autoIncrementMapping[dbType] if !ok { return fmt.Errorf("unsupported database type for auto increment: %s", dbType) @@ -233,13 +233,13 @@ func (m *Model) AutoMigrate(ctx context.Context, model interface{}) error { field := t.Field(i) // 将字段名称转换为小写并用下划线分隔 fieldName := gstr.CaseSnake(field.Name) - //如果存在 orm 中的配置 则取orm中配置的字段名 + // 如果存在 orm 中的配置 则取orm中配置的字段名 ormTag := field.Tag.Get("orm") if ormTag != "" { fieldName = ormTag } - //使用默认的字段类型映射 + // 使用默认的字段类型映射 fieldType, ok := typeMap[field.Type.Kind()] if !ok { return fmt.Errorf("unsupported field type: %s", field.Type.Kind()) @@ -258,7 +258,7 @@ func (m *Model) AutoMigrate(ctx context.Context, model interface{}) error { columns = append(columns, columnDef) } - //默认给 id 字段设置为主键,orm标签目前是配置的字段,后续考虑通过配置orm标签扩展主键自增 + // 默认给 id 字段设置为主键,orm标签目前是配置的字段,后续考虑通过配置orm标签扩展主键自增 for i, column := range columns { if gstr.Contains(column, "id") { columns[i] = column + " PRIMARY KEY UNIQUE " + autoIncrement