-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathsnapshot.go
52 lines (43 loc) · 1.59 KB
/
snapshot.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package models
import (
"database/sql/driver"
"encoding/json"
"errors"
"gorm.io/gorm"
)
const TableNameSnapshot = "snapshots"
type Snapshot struct {
Base
DeletedAt gorm.DeletedAt `json:"deleted_at"`
VersionHref string `json:"version_href" gorm:"not null"`
PublicationHref string `json:"publication_href" gorm:"not null"`
DistributionPath string `json:"distribution_path" gorm:"not null"`
RepositoryPath string `json:"repository_path" gorm:"not null"` // Path to access the repository, includes domain
DistributionHref string `json:"distribution_href" gorm:"not null"`
RepositoryConfigurationUUID string `json:"repository_configuration_uuid" gorm:"not null"`
RepositoryConfiguration RepositoryConfiguration
ContentCounts ContentCountsType `json:"content_counts" gorm:"not null,default:{}"`
AddedCounts ContentCountsType `json:"added_counts" gorm:"not null,default:{}"`
RemovedCounts ContentCountsType `json:"removed_counts" gorm:"not null,default:{}"`
}
type ContentCountsType map[string]int64
func (cc *ContentCountsType) Value() (driver.Value, error) {
if *cc == nil {
return "{}", nil
}
j, err := json.Marshal(cc)
return j, err
}
func (cc *ContentCountsType) Scan(src interface{}) error {
source, ok := src.([]byte)
if !ok {
return errors.New("Type assertion .([]byte) failed.")
}
var counts ContentCountsType
err := json.Unmarshal(source, &counts)
if err != nil {
return err
}
*cc = counts
return nil
}