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

time.Time, []byte type add alias support. (rebase master) #4992

Merged
merged 2 commits into from Jan 12, 2022
Merged

time.Time, []byte type add alias support. (rebase master) #4992

merged 2 commits into from Jan 12, 2022

Conversation

piyongcai
Copy link
Contributor

  • Do only one thing
  • Non breaking API changes
  • Tested

What did this pull request do?

1, time.Time, []byte type add alias support.
2, []byte alias type, fixed statement bind var parameter.

User Case Description

func main() {        
        type ID int64
	type TIME time.Time
	type BYTES []byte
	type TypeAlias struct {
		ID
		TIME  `gorm:"column:ftime;type:timestamptz"`
		BYTES `gorm:"column:fbytes;type:bytea"`
	}

	db, err := gorm.Open(postgres.New(postgres.Config{
		DSN: `dsn`,
		PreferSimpleProtocol: false,
	}), &gorm.Config{
		Logger:                 logger.Default.LogMode(logger.Info),
		SkipDefaultTransaction: true,
	})
	if err != nil {
		log.Fatal(err)
	}

	al := &TypeAlias{
		ID:    2,
		TIME:  TIME(time.Now()),
		BYTES: []byte{1, 2, 3},
	}

	if err := db.AutoMigrate(al); err != nil {
		t.Fatal(err)
	}

	if err := db.Create(al).Error; err != nil {
		t.Fatal(err)
	}

	al1 := &TypeAlias{}
	if err := db.First(al1).Error; err != nil {
		t.Fatal(err)
	}
}

@jinzhu jinzhu merged commit a0d6ff1 into go-gorm:master Jan 12, 2022
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