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

Conversation

ruanlang
Copy link
Contributor

@ruanlang ruanlang commented Jul 18, 2022

User Case Description

ID int64 gorm:"column:id;type:bigint(20) unsigned;primaryKey;autoIncrement:true" json:"id"
go-gorm/gorm#5505 @jinzhu @a631807682

mysql.go Outdated Show resolved Hide resolved
mysql.go Outdated Show resolved Hide resolved
Copy link
Member

@a631807682 a631807682 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ruanlang Sorry, I made a mistake.

  1. We need to support gorm:"type:int(20) AUTO_INCREMENT" and gorm:"type:int;autoIncrement", so we still need to check if AUTO_INCREMENT already exists.
  2. I'm not sure what the situation here needs to recheck TagSettings, can you give me an example?
  3. When we check AUTOINCREMENT tag, we should check the value is true or false, refer to https://github.com/go-gorm/gorm/blob/master/schema/field.go#L113

@ruanlang
Copy link
Contributor Author

We are used to using AUTO_INCREMENT in SQL statements, so check TagSettings["AUTO_INCREMENT"] @a631807682

@ruanlang
Copy link
Contributor Author

@a631807682 Sorry, use autoIncrement by convention, specifies column auto incrementable

@a631807682
Copy link
Member

a631807682 commented Jul 20, 2022

@ruanlang as the first item of the last review said, you also need to check if AUTO_INCREMENT exists, otherwise there may be cases like this:
gorm:"type:int(20) AUTO_INCREMENT" -> type:int(20) AUTO_INCREMENT AUTO_INCREMENT
because the primary key AutoIncrement is true by default

if !strings.Contains(strings.ToLower(string(field.DataType)), " auto_increment")

mysql.go Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants