teldrive/models/file.model.go

47 lines
1.2 KiB
Go
Raw Normal View History

2023-08-07 03:32:46 +08:00
package models
import (
2023-08-13 04:15:19 +08:00
"database/sql/driver"
"encoding/json"
2023-08-07 03:32:46 +08:00
"time"
)
type File struct {
2023-08-13 04:15:19 +08:00
ID string `gorm:"type:text;primary_key;default:generate_uid(16)"`
Name string `gorm:"type:text"`
Type string `gorm:"type:text"`
MimeType string `gorm:"type:text"`
Path string `gorm:"index;type:text"`
Size int64 `gorm:"type:bigint"`
Starred *bool `gorm:"default:false"`
Depth *int `gorm:"type:integer"`
UserID int `gorm:"type:bigint"`
ParentID string `gorm:"index;type:text"`
FilePart FilePart `gorm:"foreignKey:FileId;references:id;constraint:OnUpdate:CASCADE,OnDelete:SET NULL;"`
CreatedAt time.Time `gorm:"default:timezone('utc'::text, now())"`
UpdatedAt time.Time `gorm:"default:timezone('utc'::text, now())"`
}
type FilePart struct {
ID int `gorm:"type:serial4;primary_key"`
FileId string `gorm:"type:text"`
Parts *Parts `gorm:"type:jsonb"`
ChannelID int64 `gorm:"type:bigint"`
}
type Parts []Part
type Part struct {
ID int64 `json:"id"`
}
func (a Parts) Value() (driver.Value, error) {
return json.Marshal(a)
}
func (a *Parts) Scan(value interface{}) error {
if err := json.Unmarshal(value.([]byte), &a); err != nil {
return err
}
return nil
2023-08-07 03:32:46 +08:00
}