mirror of
https://github.com/TeaOSLab/EdgeAPI.git
synced 2025-11-23 15:00:25 +08:00
阶段性提交
This commit is contained in:
53
internal/db/models/file_chunk_dao.go
Normal file
53
internal/db/models/file_chunk_dao.go
Normal file
@@ -0,0 +1,53 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"errors"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
"github.com/iwind/TeaGo/Tea"
|
||||
"github.com/iwind/TeaGo/dbs"
|
||||
)
|
||||
|
||||
type FileChunkDAO dbs.DAO
|
||||
|
||||
func NewFileChunkDAO() *FileChunkDAO {
|
||||
return dbs.NewDAO(&FileChunkDAO{
|
||||
DAOObject: dbs.DAOObject{
|
||||
DB: Tea.Env,
|
||||
Table: "edgeFileChunks",
|
||||
Model: new(FileChunk),
|
||||
PkName: "id",
|
||||
},
|
||||
}).(*FileChunkDAO)
|
||||
}
|
||||
|
||||
var SharedFileChunkDAO = NewFileChunkDAO()
|
||||
|
||||
// 创建文件Chunk
|
||||
func (this *FileChunkDAO) CreateFileChunk(fileId int, data []byte) error {
|
||||
op := NewFileChunkOperator()
|
||||
op.FileId = fileId
|
||||
op.Data = data
|
||||
_, err := this.Save(op)
|
||||
return err
|
||||
}
|
||||
|
||||
// 列出所有的文件Chunk
|
||||
func (this *FileChunkDAO) FindAllFileChunks(fileId int) (result []*FileChunk, err error) {
|
||||
_, err = this.Query().
|
||||
Attr("fileId", fileId).
|
||||
AscPk().
|
||||
Slice(&result).
|
||||
FindAll()
|
||||
return
|
||||
}
|
||||
|
||||
// 删除以前的文件
|
||||
func (this *FileChunkDAO) DeleteFileChunks(fileId int) error {
|
||||
if fileId <= 0 {
|
||||
return errors.New("invalid fileId")
|
||||
}
|
||||
_, err := this.Query().
|
||||
Attr("fileId", fileId).
|
||||
Delete()
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user