teldrive/models/file.model.go
2023-08-14 02:28:06 +05:30

42 lines
1.1 KiB
Go

package models
import (
"database/sql/driver"
"encoding/json"
"time"
)
type File struct {
ID string `gorm:"type:text;primaryKey;default:generate_uid(16)"`
Name string `gorm:"type:text;not null"`
Type string `gorm:"type:text;not null"`
MimeType string `gorm:"type:text;not null"`
Path string `gorm:"type:text;index"`
Size int64 `gorm:"type:bigint"`
Starred *bool `gorm:"default:false"`
Depth *int `gorm:"type:integer"`
UserID int `gorm:"type:bigint;not null"`
Status string `gorm:"type:text"`
ParentID string `gorm:"type:text;index"`
Parts *Parts `gorm:"type:jsonb"`
ChannelID *int64 `gorm:"type:bigint"`
CreatedAt time.Time `gorm:"default:timezone('utc'::text, now())"`
UpdatedAt time.Time `gorm:"default:timezone('utc'::text, now())"`
}
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
}