gitlab.com/ignitionrobotics/web/ign-go@v1.0.0-rc4/repository/model.go (about) 1 package repository 2 3 import ( 4 "time" 5 ) 6 7 // Model represents a generic entity. A Model is part of the domain layer and is persisted by a certain Repository. 8 type Model interface { 9 // TableName returns the table/collection name for a certain model. 10 TableName() string 11 // GetID returns the unique identifier for this Model. 12 // It returns the ID of the model that has been persisted. It returns 0 if no value has been defined. 13 // For SQL environments, this would be the primary key. 14 GetID() uint 15 } 16 17 // ModelSQL implements Model for SQL backends. 18 // It provides a set of common generic fields and operations that partially implement the repository.Model interface. 19 // To use it, embed it in your application-specific repository.Model implementation. 20 type ModelSQL struct { 21 // ID contains the primary key identifier. 22 ID uint `gorm:"primary_key"` 23 // CreatedAt contains the date and time at which this model has been persisted. 24 CreatedAt time.Time `json:"created_at"` 25 // UpdatedAt contains the last date and time when this model has been updated. 26 UpdatedAt time.Time `json:"updated_at"` 27 // DeletedAt is used to implement soft record deletion. If set, the record will be considered 28 // as deleted. 29 DeletedAt *time.Time `json:"deleted_at" sql:"index"` 30 } 31 32 // GetID returns the unique identifier for this Model. 33 func (m ModelSQL) GetID() uint { 34 return m.ID 35 }