GORM Set size for the string field
In GORM package, you can specify field’s size using 2 options.
- Using
gorm:size
tag - Using
gorm:type
tag
An example using gorm:size
:
type Article struct {
gorm.Model
Source Source `json:"source" gorm:"foreignkey:SourceID"`
SourceID uint `json:"sourde_ref"`
Group string `json:"group" gorm:"not null"`
FromURL string `json:"from_url"`
URL string `json:"url" gorm:"unique;not null"`
Title string `json:"title" gorm:"size:1000"`
Description string `json:"description" gorm:"size:65535"`
Content string `json:"content" gorm:"size:65535"`
AuthorName string
AuthorEmail string
ImageURL string
ImageTitle string
Published string
PublishedParsed *time.Time
Updated string
UpdatedParsed *time.Time
Categories string
}
Another example using gorm:type
:
type User struct {
gorm.Model
Name string
Age sql.NullInt64
Birthday *time.Time
Email string `gorm:"type:varchar(100);unique_index"`
}
Check this page for more details.
Stay Connected
Subscribe at Codervlogger.com or via the RSS feed.