Datatype UUID stored as binary(16) by GORM
GORM store UUID as string or uuid type, it's more efficient and use less resources to store UUID as a binary, it would be a bummer to not use this option because we're using an ORM.
Use the type GormUUID
on the model ID as following :
import "github.com/euphoria-laxis/gorm-uuid/uuid"
type MyModel struct {
ID uuid.GormUUID `gorm:"primary_key;default:(UUID_TO_BIN(UUID()));"`
// following fields are used to match gorm.Model interface
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt gorm.DeletedAt `gorm:"index"`
}
And that's it! Gorm will do all the work to and you will have nothing to do.
Driver | Compatible | Versions |
---|---|---|
MySQL | ✔️ | V5 and V8 |
MariaDB | ✔️ | V10+ |
Postgresql | ❌ | |
SQLite | ❌ |
- Add Postgres support
- Add SQLite support
Feature | Planned | Assigned | WIP | Ready for tests | Validated | Released |
---|---|---|---|---|---|---|
Postgresql | ✔️ | ✔️ | ||||
SQLite | ✔️ | ✔️ |
This project is under MIT License.