Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: custom type implements autoIncrement #83

Merged
merged 7 commits into from
Jul 25, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,28 @@ func (dialector Dialector) DataTypeOf(field *schema.Field) string {
return dialector.getSchemaBytesType(field)
}

if field.AutoIncrement {
ruanlang marked this conversation as resolved.
Show resolved Hide resolved
sqlType := "bigint"
switch {
case field.Size <= 8:
sqlType = "tinyint"
case field.Size <= 16:
sqlType = "smallint"
case field.Size <= 24:
sqlType = "mediumint"
case field.Size <= 32:
sqlType = "int"
}

if field.GORMDataType == schema.Uint {
sqlType += " unsigned"
}

sqlType += " AUTO_INCREMENT"

return sqlType
}

return string(field.DataType)
}

Expand Down