66 "time"
77
88 "github.com/google/uuid"
9+ "gorm.io/datatypes"
910 "gorm.io/driver/postgres"
1011 "gorm.io/gorm"
1112)
@@ -19,38 +20,38 @@ const (
1920
2021// PkgMeta stores arbitrary metadata for a package.
2122type PkgMeta struct {
22- ID uuid.UUID `gorm:"type:uuid;default:gen_random_uuid();not null;primaryKey"`
23- PkgID uuid.UUID `gorm:"not null;index;constraint:OnDelete:CASCADE"`
24- Key string
25- Val string
23+ ID uuid.UUID `gorm:"type:uuid;default:gen_random_uuid();not null;primaryKey" json:"id "`
24+ PkgID uuid.UUID `gorm:"not null;index;constraint:OnDelete:CASCADE" json:"pkg_id "`
25+ Key string `gorm:"not null;index" json:"key"`
26+ Data datatypes. JSON `gorm:"type:jsonb;default:'{}'" json:"data"`
2627}
2728
2829// Pkg is the package model. Uses UUID primary key instead of gorm.Model's uint.
2930type Pkg struct {
30- ID uuid .UUID `gorm:"type:uuid;default:gen_random_uuid();not null;primaryKey"`
31- CreatedAt time.Time `gorm:"autoCreateTime"`
32- UpdatedAt time.Time `gorm:"autoUpdateTime"`
33- DeletedAt gorm.DeletedAt `gorm:"index"`
31+ ID datatypes .UUID `gorm:"type:uuid;default:gen_random_uuid();not null;primaryKey" json:"id "`
32+ CreatedAt time.Time `gorm:"autoCreateTime" json:"created_at "`
33+ UpdatedAt time.Time `gorm:"autoUpdateTime" json:"updated_at "`
34+ DeletedAt gorm.DeletedAt `gorm:"index" json:"deleted_at,omitempty" `
3435
35- Name string
36- FullVer string
37- Ver string // compatible version string between repos
38- Arch string
36+ Name string `json:"name"`
37+ FullVer string `json:"full_ver"`
38+ Ver string `json:"ver"`
39+ Arch string `json:"arch"`
3940 // RepoID is a string (not a UUID). Repositories are identified by string IDs.
40- RepoID string `gorm:"not null;index"`
41+ RepoID string `gorm:"not null;index" json:"repo_id" `
4142 // Foreign key relationship referencing Repo.ID (string).
42- Repo Repo `gorm:"constraint:OnDelete:CASCADE;foreignKey:RepoID;references:ID"`
43+ Repo Repo `gorm:"constraint:OnDelete:CASCADE;foreignKey:RepoID;references:ID" json:"-" `
4344
4445 Metas []PkgMeta
4546}
4647
4748// Repo represents a package repository. Its ID is a string.
4849type Repo struct {
49- ID string `gorm:"primaryKey"`
50- UpdAt time.Time `gorm:"autoUpdateTime"`
51- Links string
52- Type RepoType
53- Fetch string
50+ ID string `gorm:"primaryKey" json:"id" `
51+ UpdAt time.Time `gorm:"autoUpdateTime" json:"updated_at" `
52+ Links string `json:"links"`
53+ Type RepoType `json:"type"`
54+ Fetch string `json:"fetch"`
5455}
5556
5657var DB * gorm.DB
0 commit comments