go-gorm / datatypes

GORM Customized Data Types Collection
https://gorm.io/docs/data_types.html
MIT License
714 stars 108 forks source link

feat: nanoid type #226

Closed nguyenkhavi closed 1 year ago

nguyenkhavi commented 1 year ago

What did this pull request do?

User Case Description

import "gorm.io/datatypes"

type UserWithNanoID struct {
    ID   datatypes.NanoID `gorm:"nanoid" json:"id"`
    Name string
}

//Create
user := UserWithNanoID{Name: "nkvi.dev"}
DB.Create(&user)

//Query
result := UserWithNanoID{}
if err := DB.First(&result, "id = ?", user.ID).Error; err != nil {
    t.Fatalf("Failed to find user with id")
}
quyvm commented 1 year ago

Very helpful 👍

jinzhu commented 1 year ago

looks great, but seems it is better to be a independent package?