-
Notifications
You must be signed in to change notification settings - Fork 13
/
model.go
30 lines (26 loc) · 821 Bytes
/
model.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package orm
import (
"gorm.io/gorm"
)
// Model is the interface for all models.
// It only requires an Identity() method to return the primary key field
// name and value.
type Model interface {
// Identity returns the primary key field of the model.
// A very common case is that the primary key field is ID.
Identity() (fieldName string, value any)
}
// BasicModel implements Model interface with an auto increment primary key ID.
//
// BasicModel is actually the gorm.Model struct which contains the following
// fields:
// ID, CreatedAt, UpdatedAt, DeletedAt
//
// It is a good idea to embed this struct as the base struct for all models:
// type User struct {
// orm.BasicModel
// }
type BasicModel gorm.Model
func (m BasicModel) Identity() (fieldName string, value any) {
return "ID", m.ID
}