model

package
v0.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package model is the initial database driver and define the data structures corresponding to the tables.

Index

Constants

This section is empty.

Variables

View Source
var ErrRecordNotFound = gorm.ErrRecordNotFound

ErrRecordNotFound no records found

Functions

func CloseDB

func CloseDB() error

CloseDB 关闭数据库连接

实现逻辑: 1. 获取底层 *sql.DB 2. 调用 Close() 关闭连接池 3. WAL 模式下会自动执行 checkpoint

返回: error

func DeleteById

func DeleteById[T any](id int) *gorm.DB

func FindFirstByID

func FindFirstByID[T any](id int) *T

func FindItems

func FindItems[T any]() []*T

func GetDB

func GetDB() *gorm.DB

GetDB get db

func InitDB

func InitDB()

InitDB connect database

func InitSqlite

func InitSqlite()

InitSqlite 初始化 SQLite 数据库连接

实现逻辑(与代码顺序一致): 1. 从 config.GetDBFile() 获取 DSN,并展开用户目录(~/) 2. 确保数据库文件所在目录存在(权限 0755) 3. 使用 gorm.io/driver/sqlite 打开数据库(禁用 SQL 日志,启用 PrepareStmt) 4. 配置连接池(SetMaxOpenConns=2, SetMaxIdleConns=2, SetConnMaxLifetime=0) 5. 执行 PRAGMA 兜底(journal_mode=WAL, synchronous=NORMAL, busy_timeout=5000, foreign_keys=ON, temp_store=MEMORY) 6. 自动迁移(AutoMigrate)模型表结构

参数: 无 返回: 无(失败时 panic)

func Save

func Save(value interface{}) *gorm.DB

func ToList

func ToList(items []*Quick) []list.Item

Types

type File

type File struct {
	*bdpan.FileInfo `gorm:"-"`
	ID              uint64 `gorm:"primaryKey;"`
	FSID            uint64 `json:"fs_id" gorm:"column:fs_id"`
	Path            string `json:"path"`
	Dir             string `json:"dir"`
	Size            int    `json:"size"`
	FileType        int    `json:"isdir" gorm:"column:is_dir"`
	Filename        string `json:"filename"`
	ServerFilename  string `json:"server_filename"`
	Category        int    `json:"category"`
	Dlink           string `json:"dlink"`
	MD5             string `json:"md5"`
	ServerCTime     int64  `json:"server_ctime"`
	ServerMTime     int64  `json:"server_mtime"`
	LocalCTime      int64  `json:"local_ctime"`
	LocalMTime      int64  `json:"local_mtime"`

	// custom
	IsRefresh int  `json:"is_refresh"`
	Level     int  `json:"level"`
	IsSelect  bool `gorm:"-" json:"is_select"` // 是否选中,tui 表格使用
	ORMModel
}

生成 sqlite3 建表语句,开头加上删除语句 sqlite3 字段要符合 gorm 命名规则

func FindFilesByDir

func FindFilesByDir(dir string, page int) []*File

func FindFilesPrefixPath

func FindFilesPrefixPath(path string, isDir bool) []*File

func FindFirstByPath

func FindFirstByPath(path string) *File

func FindNeedRefreshFiles

func FindNeedRefreshFiles(path string) []*File

func NewFile

func NewFile(f *bdpan.FileInfo) *File

func NewFiles

func NewFiles(files []*bdpan.FileInfo) []*File

func NewRootFile

func NewRootFile() *File

func (*File) Fill

func (f *File) Fill() *File

func (*File) Resave

func (f *File) Resave() *gorm.DB

func (*File) Save

func (f *File) Save() *gorm.DB

func (File) TableName

func (File) TableName() string

func (*File) ToQuick

func (f *File) ToQuick() *Quick

type ORMModel

type ORMModel struct {
	CreateTime time.Time `json:"create_time"`
	UpdateTime time.Time `json:"update_time"`
	IsDelete   int8      `json:"is_delete" form:"is_delete" gorm:"index"`
}

func (*ORMModel) Init

func (o *ORMModel) Init()

func (ORMModel) IsNil

func (o ORMModel) IsNil() bool

type Pan

type Pan struct {
	*bdpan.GetPanInfoRes `gorm:"-"`
	ID                   int   `gorm:"primaryKey;"`
	Total                int64 `json:"total,omitempty"`
	Free                 int64 `json:"free,omitempty"`
	Expire               bool  `json:"expire,omitempty"`
	Used                 int64 `json:"used,omitempty"`
}

func NewPan

func NewPan(id int, pan *bdpan.GetPanInfoRes) *Pan

type Quick

type Quick struct {
	ID       uint64 `gorm:"primaryKey;"`
	Filename string `json:"filename"`
	Path     string `json:"path"`
	Key      string `json:"key"`
	ORMModel
}

func (Quick) Description

func (q Quick) Description() string

func (Quick) FilterValue

func (q Quick) FilterValue() string

func (Quick) TableName

func (Quick) TableName() string

func (Quick) Title

func (q Quick) Title() string

type Task added in v0.0.5

type Task struct {
	ID              string  `gorm:"primaryKey;column:id" json:"id"`
	Type            string  `gorm:"column:type;index" json:"type"`
	Identity        string  `gorm:"column:identity;uniqueIndex" json:"identity"`
	Status          string  `gorm:"column:status;index" json:"status"`
	Progress        float64 `gorm:"column:progress" json:"progress"`
	TotalBytes      int64   `gorm:"column:total_bytes" json:"total_bytes"`
	DownloadedBytes int64   `gorm:"column:downloaded_bytes" json:"downloaded_bytes"`
	PID             int     `gorm:"column:pid" json:"pid"`
	Hostname        string  `gorm:"column:hostname" json:"hostname"`
	Concurrency     int     `gorm:"column:concurrency" json:"concurrency"`
	StartTime       string  `gorm:"column:start_time;index" json:"start_time"`
	UpdateTime      string  `gorm:"column:update_time;index" json:"update_time"`
	SpeedBPS        int64   `gorm:"column:speed_bps" json:"speed_bps"`
	ETASeconds      int64   `gorm:"column:eta_seconds" json:"eta_seconds"`
	Error           string  `gorm:"column:error" json:"error"`
	CancelRequested int     `gorm:"column:cancel_requested" json:"cancel_requested"`
	Data            string  `gorm:"column:data;type:text" json:"data"`
	Version         int     `gorm:"column:version" json:"version"`
}

func NewTask added in v0.0.5

func NewTask(id, typ, identity string, totalBytes int64, pid int, hostname string, concurrency int, data string) *Task

NewTask 构造一个运行中的 Task,填充起始字段。

func (Task) TableName added in v0.0.5

func (Task) TableName() string

type TaskChild added in v0.0.5

type TaskChild struct {
	ID         int64  `gorm:"primaryKey;column:id" json:"id"`
	TaskID     string `gorm:"column:task_id;index" json:"task_id"`
	Name       string `gorm:"column:name" json:"name"`
	Path       string `gorm:"column:path" json:"path"`
	Size       int64  `gorm:"column:size" json:"size"`
	Downloaded int64  `gorm:"column:downloaded" json:"downloaded"`
	Status     string `gorm:"column:status;index" json:"status"`
	Error      string `gorm:"column:error" json:"error"`
	UpdateTime string `gorm:"column:update_time;index" json:"update_time"`
}

func (TaskChild) TableName added in v0.0.5

func (TaskChild) TableName() string

type UploadHistory added in v0.0.3

type UploadHistory struct {
	FSID           uint64 `json:"fs_id" gorm:"primaryKey;column:fs_id"`
	Path           string `json:"path"`
	Size           uint64 `json:"size"`
	ServerFilename string `json:"server_filename"`
	Category       int32  `json:"category"`
	MD5            string `json:"md5"`
	LocalMD5       string `json:"local_md5"`
	CTime          uint64 `json:"ctime"`
	MTime          uint64 `json:"mtime"`
	ORMModel
}

func FindUploadHistoryByLocalMD5 added in v0.0.3

func FindUploadHistoryByLocalMD5(md5 string) *UploadHistory

func (UploadHistory) TableName added in v0.0.3

func (UploadHistory) TableName() string

type User

type User struct {
	*bdpan.GetUserInfoRes `gorm:"-"`
	ID                    int    `gorm:"primaryKey;"`
	Uk                    int    `json:"uk,omitempty"`
	AvatarUrl             string `json:"avatar_url,omitempty"`
	BaiduName             string `json:"baidu_name,omitempty"`
	NetdiskName           string `json:"netdisk_name,omitempty"`
	VipType               int32  `json:"vip_type,omitempty"`
	VipName               string `json:"vip_name,omitempty"`
}

func NewUser

func NewUser(user *bdpan.GetUserInfoRes) *User

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL