database

package
v2.0.18 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2025 License: MIT Imports: 21 Imported by: 0

Documentation

Overview

Package database 提供数据库相关的操作功能

Package database 提供数据库操作相关功能

Package database 提供数据库操作相关功能

Package database 提供了数据库相关的功能实现

Index

Constants

View Source
const (
	BackupFileName = "badgerhold_backup.bak" // 备份文件名
)

Variables

This section is empty.

Functions

func AddColumn

func AddColumn(db *sql.DB, tableName string, columnName string, columnType string) error

AddColumn 在表中添加新列

参数:

  • db *sql.DB: 数据库连接实例
  • tableName string: 要添加列的表名
  • columnName string: 要添加的列名
  • columnType string: 列的数据类型

返回值:

  • error: 添加过程中的错误,如果成功则为nil

func AggressiveValueLogGC

func AggressiveValueLogGC(db *badgerhold.Store) error

AggressiveValueLogGC 执行激进的值日志垃圾回收

参数:

  • db *badgerhold.Store: 数据库实例

返回值:

  • error: 如果GC过程中发生错误,返回错误信息

func BackupDatabase

func BackupDatabase(store *badgerhold.Store, backupDir string) error

BackupDatabase 备份数据库到指定文件 参数:

  • store: *badgerhold.Store 表示数据库实例
  • backupPath: string 表示备份文件的路径

返回值:

  • error: 如果备份过程中出现错误,返回错误信息

func CheckDatabaseStatus

func CheckDatabaseStatus(store *badgerhold.Store) error

CheckDatabaseStatus 检查数据库是否损坏 参数:

  • store: *badgerhold.Store 表示数据库实例

返回值:

  • error: 如果数据库损坏或无法访问,返回错误信息

func ClearDatabase

func ClearDatabase(db *badgerhold.Store) error

ClearDatabase 清空数据库中所有数据

参数:

  • db *badgerhold.Store: 数据库实例

返回值:

  • error: 如果清空过程中发生错误,返回错误信息

func Count

func Count(db *sql.DB, tableName string, conditions []string, args []interface{}) (int, error)

Count 返回表中记录总数

参数:

  • db *sql.DB: 数据库连接实例
  • tableName string: 要查询的表名
  • conditions []string: WHERE条件语句
  • args []interface{}: conditions中的参数值

返回值:

  • int: 记录总数
  • error: 查询过程中的错误,如果成功则为nil

func CreateFileSegmentStorageTable

func CreateFileSegmentStorageTable(db *sql.DB) error

CreateFileSegmentStorageTable 创建文件片段存储表 参数:

  • db: SQLite数据库连接实例

返回值:

  • error: 如果创建成功返回nil,否则返回错误信息

func CreateTable

func CreateTable(db *sql.DB, tableName string, columns []string) error

CreateTable 创建数据库表

参数:

  • db *sql.DB: 数据库连接实例
  • tableName string: 要创建的表名
  • columns []string: 列定义字符串的切片,如 []string{"id INTEGER PRIMARY KEY", "name TEXT"}

返回值:

  • error: 创建过程中的错误,如果成功则为nil

func Delete

func Delete(db *sql.DB, tableName string, conditions []string, args []interface{}) error

Delete 在表中删除数据

参数:

  • db *sql.DB: 数据库连接实例
  • tableName string: 要删除数据的表名
  • conditions []string: WHERE条件语句
  • args []interface{}: conditions中的参数值

返回值:

  • error: 删除过程中的错误,如果成功则为nil

func Exists

func Exists(db *sql.DB, tableName string, conditions []string, args []interface{}) (bool, error)

Exists 查询是否存在满足条件的记录

参数:

  • db *sql.DB: 数据库连接实例
  • tableName string: 要查询的表名
  • conditions []string: WHERE条件语句
  • args []interface{}: conditions中的参数值

返回值:

  • bool: 是否存在满足条件的记录
  • error: 查询过程中的错误,如果成功则为nil

func ForceCleanup

func ForceCleanup(db *badgerhold.Store) error

ForceCleanup 强制清理数据库

参数:

  • db *badgerhold.Store: 数据库实例

返回值:

  • error: 如果清理过程中发生错误,返回错误信息

func ForceValueLogGC

func ForceValueLogGC(db *badgerhold.Store, ratio float64) error

ForceValueLogGC 强制执行 value log 垃圾回收

参数:

  • db *badgerhold.Store: 数据库实例
  • ratio float64: GC触发阈值(0.0-1.0)

返回值:

  • error: 如果GC过程中发生错误,返回错误信息

func InitDBTable

func InitDBTable(lc fx.Lifecycle, input InitDBTableInput) error

InitDBTable 初始化 创建数据库 并设置相关的生命周期钩子 参数:

  • lc: fx.Lifecycle 用于管理应用生命周期的对象
  • input: InitDBTableInput 包含初始化所需的输入参数

返回值:

  • error 如果初始化过程中发生错误,则返回相应的错误信息

func Insert

func Insert(db *sql.DB, tableName string, data map[string]interface{}) error

Insert 向表中插入数据

参数:

  • db *sql.DB: 数据库连接实例
  • tableName string: 要插入数据的表名
  • data map[string]interface{}: 键为列名,值为对应的数据

返回值:

  • error: 插入过程中的错误,如果成功则为nil

func ModifyColumnType

func ModifyColumnType(db *sql.DB, tableName string, columnName string, newColumnType string) error

ModifyColumnType 修改数据库表中指定列的数据类型

参数:

  • db *sql.DB: 数据库连接实例
  • tableName string: 要修改的表名
  • columnName string: 要修改的列名
  • newColumnType string: 新的数据类型

返回值:

  • error: 修改过程中的错误,如果成功则为nil

func NewBadgerDB

func NewBadgerDB(ctx context.Context) (*badgerhold.Store, error)

NewBadgerDB 创建并初始化一个新的BadgerDB实例

参数:

  • ctx context.Context: 上下文对象,用于控制数据库生命周期

返回值:

  • *badgerhold.Store: BadgerDB存储实例
  • error: 如果初始化过程中发生错误,返回错误信息

func NewSqliteDB

func NewSqliteDB(ctx context.Context) (*sql.DB, error)

NewSqliteDB 创建并初始化一个新的SQLite数据库连接

参数:

  • ctx context.Context: 上下文对象,用于控制后台任务的生命周期

返回值:

  • *sql.DB: 数据库连接实例
  • error: 初始化过程中的错误,如果成功则为nil

func RestoreDatabaseFromBackup

func RestoreDatabaseFromBackup(options badgerhold.Options, store *badgerhold.Store, backupPath, dbPath, valueDirPath string) error

RestoreDatabaseFromBackup 从备份文件恢复数据库 参数:

  • backupPath: string 表示备份文件的路径
  • dbPath: string 表示数据库文件的路径

返回值:

  • error: 如果恢复过程中出现错误,返回错误信息

func Select

func Select(db *sql.DB, tableName string, columns []string, conditions []string, args []interface{}, start, limit int, orderBy string) (*sql.Rows, error)

Select 从表中查询数据

参数:

  • db *sql.DB: 数据库连接实例
  • tableName string: 要查询的表名
  • columns []string: 要查询的列名
  • conditions []string: WHERE条件语句
  • args []interface{}: conditions中的参数值
  • start int: 查询的起始行
  • limit int: 查询的行数
  • orderBy string: 排序字段,可包含多个字段,如"field1 ASC, field2 DESC"

返回值:

  • *sql.Rows: 查询结果集
  • error: 查询过程中的错误,如果成功则为nil

func SelectOne

func SelectOne(db *sql.DB, tableName string, columns []string, conditions []string, args []interface{}) (*sql.Row, error)

SelectOne 从表中查询一条数据

参数:

  • db *sql.DB: 数据库连接实例
  • tableName string: 要查询的表名
  • columns []string: 要查询的列名
  • conditions []string: WHERE条件语句
  • args []interface{}: conditions中的参数值

返回值:

  • *sql.Row: 查询结果
  • error: 查询过程中的错误,如果成功则为nil

func ToFileSegmentStorage

func ToFileSegmentStorage(m *pb.FileSegmentStorageSql) (*pb.FileSegmentStorage, error)

ToFileSegmentStorage 将 FileSegmentStorageSql 转换为 FileSegmentStorage

func ToFileSegmentStorageSql

func ToFileSegmentStorageSql(m *pb.FileSegmentStorage) (*pb.FileSegmentStorageSql, error)

ToFileSegmentStorageSql 将 FileSegmentStorage 转换为 FileSegmentStorageSql

func TruncateTable

func TruncateTable(db *sql.DB, tableName string, vacuum bool) (int64, error)

TruncateTable 删除表中所有数据

参数:

  • db *sql.DB: 数据库连接实例
  • tableName string: 要清空的表名
  • vacuum bool: 是否在删除后执行VACUUM操作来回收空间

返回值:

  • int64: 删除的记录数
  • error: 删除过程中的错误,如果成功则为nil

func TruncateTableTx

func TruncateTableTx(db *sql.DB, tx *sql.Tx, tableName string) (int64, error)

TruncateTableTx 在事务中删除表中所有数据

参数:

  • db *sql.DB: 数据库连接实例
  • tx *sql.Tx: 事务实例
  • tableName string: 要清空的表名

返回值:

  • int64: 删除的记录数
  • error: 删除过程中的错误,如果成功则为nil

func TxDelete

func TxDelete(db *sql.DB, tx *sql.Tx, tableName string, conditions []string, args []interface{}) error

TxDelete 在事务中删除表中数据

参数:

  • db *sql.DB: 数据库连接实例
  • tx *sql.Tx: 事务实例
  • tableName string: 要删除数据的表名
  • conditions []string: WHERE条件语句
  • args []interface{}: conditions中的参数值

返回值:

  • error: 删除过程中的错误,如果成功则为nil

func TxInsert

func TxInsert(db *sql.DB, tx *sql.Tx, tableName string, data map[string]interface{}) error

TxInsert 在事务中向表中插入数据

参数:

  • db *sql.DB: 数据库连接实例
  • tx *sql.Tx: 事务实例
  • tableName string: 要插入数据的表名
  • data map[string]interface{}: 键为列名,值为对应的数据

返回值:

  • error: 插入过程中的错误,如果成功则为nil

func Update

func Update(db *sql.DB, tableName string, data map[string]interface{}, conditions []string, args []interface{}) error

Update 在表中更新数据

参数:

  • db *sql.DB: 数据库连接实例
  • tableName string: 要更新的表名
  • data map[string]interface{}: 键为列名,值为新的数据
  • conditions []string: WHERE条件语句
  • args []interface{}: conditions中的参数值

返回值:

  • error: 更新过程中的错误,如果成功则为nil

Types

type DB

type DB struct {
	BadgerDB *badgerhold.Store // BadgerDB数据库实例
	SqliteDB *sql.DB           // SqliteDB数据库实例
}

DB 数据库结构体,包含BadgerDB和SqliteDB实例

type DownloadFileStore

type DownloadFileStore struct {
	// contains filtered or unexported fields
}

DownloadFileStore 管理下载文件记录的存储

func NewDownloadFileStore

func NewDownloadFileStore(store *badgerhold.Store) *DownloadFileStore

NewDownloadFileStore 创建一个新的下载文件存储管理器

func (*DownloadFileStore) Delete

func (s *DownloadFileStore) Delete(taskID string) error

Delete 删除指定任务ID的下载文件记录 参数:

  • taskID: 任务的唯一标识符

返回值:

  • error: 如果删除过程中出现错误,返回相应的错误信息

func (*DownloadFileStore) DeleteTx

func (s *DownloadFileStore) DeleteTx(txn *badger.Txn, taskID string) error

Delete 删除指定任务ID的下载文件记录 参数:

  • txn: Badger 事务对象
  • taskID: 任务的唯一标识符

返回值:

  • error: 如果删除过程中出现错误,返回相应的错误信息

func (*DownloadFileStore) FindByFileID

func (s *DownloadFileStore) FindByFileID(fileID string) ([]*pb.DownloadFileRecord, error)

FindByFileID 根据文件ID查找下载记录 参数:

  • fileID: 文件的唯一标识符

返回值:

  • []*pb.DownloadFileRecord: 符合条件的下载文件记录列表
  • error: 如果查找过程中出现错误,返回相应的错误信息

func (*DownloadFileStore) FindByStatus

func (s *DownloadFileStore) FindByStatus(status pb.DownloadStatus) ([]*pb.DownloadFileRecord, error)

FindByStatus 根据下载状态查找文件记录 参数:

  • status: 下载状态

返回值:

  • []*pb.DownloadFileRecord: 符合条件的下载文件记录列表
  • error: 如果查找过程中出现错误,返回相应的错误信息

func (*DownloadFileStore) Get

Get 根据任务ID获取下载文件记录 参数:

  • taskID: 任务的唯一标识符

返回值:

  • *pb.DownloadFileRecord: 找到的下载文件记录
  • bool: 记录是否存在
  • error: 如果查找过程中出现错误,返回相应的错误信息

func (*DownloadFileStore) GetTx

func (s *DownloadFileStore) GetTx(txn *badger.Txn, taskID string) (*pb.DownloadFileRecord, bool, error)

Get 根据任务ID获取下载文件记录 参数:

  • txn: Badger 事务对象
  • taskID: 任务的唯一标识符

返回值:

  • *pb.DownloadFileRecord: 找到的下载文件记录
  • bool: 记录是否存在
  • error: 如果查找过程中出现错误,返回相应的错误信息

func (*DownloadFileStore) Insert

func (s *DownloadFileStore) Insert(record *pb.DownloadFileRecord) error

Insert 插入一条新的下载文件记录 参数:

  • record: 要插入的下载文件记录

返回值:

  • error: 如果插入过程中出现错误,返回相应的错误信息

func (*DownloadFileStore) InsertTx

func (s *DownloadFileStore) InsertTx(txn *badger.Txn, record *pb.DownloadFileRecord) error

InsertTx 在事务中插入一条新的下载文件记录 参数:

  • txn: Badger 事务对象
  • record: 要插入的下载文件记录

返回值:

  • error: 如果插入过程中出现错误,返回相应的错误信息

func (*DownloadFileStore) QueryDownloadTaskRecordsTx

func (s *DownloadFileStore) QueryDownloadTaskRecordsTx(txn *badger.Txn, start, limit int, options ...QueryOption) ([]*pb.DownloadFileRecord, uint64, error)

QueryDownloadTaskRecordsTx 在事务中执行下载任务记录的查询 参数:

  • txn: *badger.Txn 数据库事务对象
  • start: int 查询的起始位置
  • limit: int 返回的最大记录数
  • options: ...QueryOption 查询选项(如状态过滤、时间范围等)

返回值:

  • []*pb.DownloadFileRecord: 下载任务记录列表
  • uint64: 符合查询条件的总记录数
  • error: 如果查询过程中发生错误,返回相应错误

func (*DownloadFileStore) Update

func (s *DownloadFileStore) Update(record *pb.DownloadFileRecord) error

Update 更新现有的下载文件记录 参数:

  • record: 要更新的下载文件记录

返回值:

  • error: 如果更新过程中出现错误,返回相应的错误信息

func (*DownloadFileStore) UpdateTx

func (s *DownloadFileStore) UpdateTx(txn *badger.Txn, record *pb.DownloadFileRecord) error

Update 更新现有的下载文件记录 参数:

  • txn: Badger 事务对象
  • record: 要更新的下载文件记录

返回值:

  • error: 如果更新过程中出现错误,返回相应的错误信息

type DownloadSegmentStore

type DownloadSegmentStore struct {
	// contains filtered or unexported fields
}

DownloadSegmentStore 管理下载片段记录的存储

func NewDownloadSegmentStore

func NewDownloadSegmentStore(store *badgerhold.Store) *DownloadSegmentStore

NewDownloadSegmentStore 创建一个新的下载片段存储管理器

func (*DownloadSegmentStore) Delete

func (s *DownloadSegmentStore) Delete(segmentID string) error

Delete 删除指定片段ID的下载片段记录 参数:

  • segmentID: 片段的唯一标识符

返回值:

  • error: 如果删除过程中出现错误,返回相应的错误信息

func (*DownloadSegmentStore) DeleteTx

func (s *DownloadSegmentStore) DeleteTx(txn *badger.Txn, segmentID string) error

DeleteTx 在事务中删除指定片段ID的下载片段记录 参数:

  • txn: *badger.Txn 数据库事务对象
  • segmentID: string 片段的唯一标识符

返回值:

  • error: 如果删除过程中出现错误,返回相应的错误信息

func (*DownloadSegmentStore) FindByTaskID

func (s *DownloadSegmentStore) FindByTaskID(taskID string, includeContent ...bool) ([]*pb.DownloadSegmentRecord, error)

FindByTaskID 根据任务ID查找相关的片段记录 参数:

  • taskID: 任务的唯一标识符
  • includeContent: 可选参数,是否包含片段内容,默认为 false

返回值:

  • []*pb.DownloadSegmentRecord: 符合条件的下载片段记录列表
  • error: 如果查找过程中出现错误,返回相应的错误信息

func (*DownloadSegmentStore) FindByTaskIDAndStatus

func (s *DownloadSegmentStore) FindByTaskIDAndStatus(taskID string, status pb.SegmentDownloadStatus, includeContent ...bool) ([]*pb.DownloadSegmentRecord, error)

FindByTaskIDAndStatus 根据任务ID和状态查找片段记录 参数:

  • taskID: 任务的唯一标识符
  • status: 片段下载状态

返回值:

  • []*pb.DownloadSegmentRecord: 符合条件的下载片段记录列表
  • error: 如果查找过程中出现错误,返回相应的错误信息

func (*DownloadSegmentStore) FindByTaskIDTx

func (s *DownloadSegmentStore) FindByTaskIDTx(txn *badger.Txn, taskID string, includeContent ...bool) ([]*pb.DownloadSegmentRecord, error)

FindByTaskIDTx 在事务中根据任务ID查找相关的片段记录(不包含片段内容) 参数:

  • txn: *badger.Txn 数据库事务对象
  • taskID: string 任务的唯一标识符

返回值:

  • []*pb.DownloadSegmentRecord: 符合条件的下载片段记录列表(不含片段内容)
  • error: 如果查找过程中出现错误,返回相应的错误信息

func (*DownloadSegmentStore) FindSegmentContent

func (s *DownloadSegmentStore) FindSegmentContent(segmentID string) ([]byte, error)

FindSegmentContent 根据片段ID获取片段内容 参数:

  • segmentID: 片段的唯一标识符

返回值:

  • []byte: 片段内容
  • error: 如果查找过程中出现错误,返回相应的错误信息

func (*DownloadSegmentStore) Get

Get 根据片段ID获取下载片段记录 参数:

  • segmentID: 片段的唯一标识符

返回值:

  • *pb.DownloadSegmentRecord: 找到的下载片段记录
  • bool: 记录是否存在
  • error: 如果查找过程中出现错误,返回相应的错误信息

func (*DownloadSegmentStore) GetDownloadSegmentBySegmentID

func (s *DownloadSegmentStore) GetDownloadSegmentBySegmentID(segmentID string) (*pb.DownloadSegmentRecord, bool, error)

GetDownloadSegmentBySegmentID 根据片段ID获取下载片段记录 参数:

  • segmentID: string 片段的唯一标识符

返回值:

  • *pb.UploadSegmentRecord: 获取到的上传片段记录
  • bool: 记录是否存在
  • error: 如果发生系统错误返回错误信息,记录不存在则返回nil

func (*DownloadSegmentStore) GetTx

func (s *DownloadSegmentStore) GetTx(txn *badger.Txn, segmentID string) (*pb.DownloadSegmentRecord, bool, error)

Get 根据片段ID获取下载片段记录 参数:

  • txn: *badger.Txn 数据库事务对象
  • segmentID: 片段的唯一标识符

返回值:

  • *pb.DownloadSegmentRecord: 找到的下载片段记录
  • bool: 记录是否存在
  • error: 如果查找过程中出现错误,返回相应的错误信息

func (*DownloadSegmentStore) Insert

Insert 插入一条新的下载片段记录 参数:

  • record: 要插入的下载片段记录

返回值:

  • error: 如果插入过程中出现错误,返回相应的错误信息

func (*DownloadSegmentStore) InsertTx

func (s *DownloadSegmentStore) InsertTx(txn *badger.Txn, record *pb.DownloadSegmentRecord) error

InsertTx 在事务中插入一条新的下载片段记录 参数:

  • txn: *badger.Txn 数据库事务对象
  • record: *pb.DownloadSegmentRecord 要插入的下载片段记录

返回值:

  • error: 如果插入过程中出现错误,返回相应的错误信息

func (*DownloadSegmentStore) TaskByFileID

func (s *DownloadSegmentStore) TaskByFileID(taskId string) (int, []int64, int, error)

TaskByFileID 根据文件ID查找相关的片段记录和下载状态 参数:

  • taskId: 任务唯一标识

返回值:

  • int: 总片段数
  • []int64: 已下载完成的片段索引列表
  • int: 数据片段大小(不含校验片段)
  • error: 如果查找过程中出现错误,返回相应的错误信息

func (*DownloadSegmentStore) Update

func (s *DownloadSegmentStore) Update(record *pb.DownloadSegmentRecord, validateContent ...bool) error

Update 更新下载片段记录 只更新与现有记录不同的字段 参数:

  • record: *pb.DownloadSegmentRecord 要更新的记录
  • validateContent: bool 是否校验内容哈希(可选)

返回值:

  • error: 如果更新过程中出现错误,返回相应的错误信息

func (*DownloadSegmentStore) UpdateTx

func (s *DownloadSegmentStore) UpdateTx(txn *badger.Txn, record *pb.DownloadSegmentRecord, validateContent ...bool) error

UpdateTx 在事务中更新下载片段记录,只更新与现有记录不同的字段 参数:

  • txn: *badger.Txn 数据库事务对象
  • record: *pb.DownloadSegmentRecord 要更新的记录
  • validateContent: ...bool 是否校验内容哈希(可选参数)

返回值:

  • error: 如果更新过程中出现错误,返回相应的错误信息

type FileAssetStore

type FileAssetStore struct {
	// contains filtered or unexported fields
}

FileAssetStore 处理 FileAssetRecord 的数据库操作

func NewFileAssetStore

func NewFileAssetStore(db *badgerhold.Store) *FileAssetStore

NewFileAssetStore 创建一个新的 FileAssetStore 实例 参数:

  • db: *badgerhold.Store 数据库连接实例

返回值:

  • *FileAssetStore: 新创建的 FileAssetStore 实例

func (*FileAssetStore) ClearAllFileAssets

func (s *FileAssetStore) ClearAllFileAssets() error

ClearAllFileAssets 清空所有的文件资产记录 返回值:

  • error: 如果清空成功返回nil,否则返回错误信息

func (*FileAssetStore) CreateFileAsset

func (s *FileAssetStore) CreateFileAsset(asset *pb.FileAssetRecord) error

CreateFileAsset 创建一个新的文件资产记录 参数:

  • asset: *pb.FileAssetRecord 要创建的文件资产记录

返回值:

  • error: 如果创建成功返回nil,否则返回错误信息

func (*FileAssetStore) DeleteFileAsset

func (s *FileAssetStore) DeleteFileAsset(fileID string) error

DeleteFileAsset 删除文件资产记录 参数:

  • fileID: string 要删除的文件资产记录的ID

返回值:

  • error: 如果删除成功返回nil,否则返回错误信息

func (*FileAssetStore) GetFileAssetByOwnerAndFileID added in v2.0.18

func (s *FileAssetStore) GetFileAssetByOwnerAndFileID(pubkeyHash []byte, fileID string) (*pb.FileAssetRecord, bool, error)

GetFileAssetByOwnerAndFileID 通过所有者的公钥哈希和文件唯一标识获取FileAssetRecord 参数:

  • pubkeyHash: []byte 所有者的公钥哈希
  • fileID: string 文件唯一标识

返回值:

  • *pb.FileAssetRecord: 查询到的文件资产记录
  • bool: 是否找到记录
  • error: 如果查询成功返回nil,否则返回错误信息

func (*FileAssetStore) ListAllFileAssets

func (s *FileAssetStore) ListAllFileAssets() ([]*pb.FileAssetRecord, error)

ListAllFileAssets 列出所有文件资产记录 返回值:

  • []*pb.FileAssetRecord: 所有文件资产记录的切片
  • error: 如果列出成功返回nil,否则返回错误信息

func (*FileAssetStore) QueryFileAssets

func (s *FileAssetStore) QueryFileAssets(pubkeyHash []byte, start, limit int, param string, options ...QueryOption) ([]*pb.FileAssetRecord, uint64, error)

QueryFileAssets 查询文件资产记录 参数:

  • pubkeyHash: []byte 所有者的公钥哈希
  • start: int 查询的起始位置
  • limit: int 查询的最大记录数
  • param: string 搜索参数
  • options: ...QueryOption 可选的查询选项

返回值:

  • []*pb.FileAssetRecord: 查询到的文件资产记录切片
  • uint64: 符合查询条件的总记录数
  • error: 如果查询成功返回nil,否则返回错误信息

func (*FileAssetStore) SetFileShared added in v2.0.18

func (s *FileAssetStore) SetFileShared(pubkeyHash []byte, fileID string, shareAmount float64) error

SetFileShared 将文件设置为共享状态并设置共享金额 参数:

  • pubkeyHash: []byte 所有者的公钥哈希
  • fileID: string 文件唯一标识
  • shareAmount: float64 共享金额

返回值:

  • error: 如果设置成功返回nil,否则返回错误信息

func (*FileAssetStore) UnsetFileShared added in v2.0.18

func (s *FileAssetStore) UnsetFileShared(pubkeyHash []byte, fileID string) error

UnsetFileShared 取消文件的共享状态 参数:

  • pubkeyHash: []byte 所有者的公钥哈希
  • fileID: string 文件唯一标识

返回值:

  • error: 如果取消成功返回nil,否则返回错误信息

func (*FileAssetStore) UpdateFileAsset

func (s *FileAssetStore) UpdateFileAsset(asset *pb.FileAssetRecord) error

UpdateFileAsset 更新文件资产记录 参数:

  • asset: *pb.FileAssetRecord 要更新的文件资产记录

返回值:

  • error: 如果更新成功返回nil,否则返回错误信息

type FileSegmentStorageSqlStore

type FileSegmentStorageSqlStore struct {
	// contains filtered or unexported fields
}

FileSegmentStorageSqlStore 文件片段存储的SQLite实现

func NewFileSegmentStorageSqlStore

func NewFileSegmentStorageSqlStore(sqlite *sql.DB) *FileSegmentStorageSqlStore

NewFileSegmentStorageSqlStore 创建新的文件片段存储实例 参数:

  • sqlite: SQLite数据库连接实例

返回值:

  • *FileSegmentStorageSqlStore: 新创建的文件片段存储实例

func (*FileSegmentStorageSqlStore) CreateFileSegmentStorage

func (rss *FileSegmentStorageSqlStore) CreateFileSegmentStorage(fileSegmentStorage *pb.FileSegmentStorageSql) error

CreateFileSegmentStorage 创建新的文件片段存储记录 参数:

  • fileSegmentStorage: 要存储的文件片段信息

返回值:

  • error: 如果创建成功返回nil,否则返回错误信息

func (*FileSegmentStorageSqlStore) DeleteFileSegmentStorage

func (s *FileSegmentStorageSqlStore) DeleteFileSegmentStorage(segmentID string) error

DeleteFileSegmentStorage 删除文件片段存储记录 参数:

  • segmentID: 要删除的片段ID

返回值:

  • error: 如果删除成功返回nil,否则返回错误信息

func (*FileSegmentStorageSqlStore) DeleteFileSegmentStoragesByFileID

func (s *FileSegmentStorageSqlStore) DeleteFileSegmentStoragesByFileID(fileID string, pubkeyHash []byte) error

DeleteFileSegmentStoragesByFileID 根据文件ID和公钥哈希删除所有相关的文件片段存储记录 参数:

  • fileID: 文件唯一标识
  • pubkeyHash: 公钥哈希

返回值:

  • error: 如果删除成功返回nil,否则返回错误信息

func (*FileSegmentStorageSqlStore) GetFileSegmentStorage

func (rss *FileSegmentStorageSqlStore) GetFileSegmentStorage(segmentID string) (*pb.FileSegmentStorageSql, error)

GetFileSegmentStorage 根据片段ID获取文件片段存储记录 参数:

  • segmentID: 片段唯一标识

返回值:

  • *pb.FileSegmentStorageSql: 查询到的文件片段存储记录
  • error: 如果查询成功返回nil,否则返回错误信息

func (*FileSegmentStorageSqlStore) GetFileSegmentStorageByFileIDAndSegment

func (s *FileSegmentStorageSqlStore) GetFileSegmentStorageByFileIDAndSegment(fileID string, pubkeyHash []byte, segmentID string, segmentIndex int64) (*pb.FileSegmentStorageSql, bool, error)

GetFileSegmentStorageByFileIDAndSegment 根据文件ID、公钥哈希、片段ID和片段索引获取单个文件片段存储记录 参数:

  • fileID: 文件唯一标识
  • pubkeyHash: 公钥哈希
  • segmentID: 片段唯一标识
  • segmentIndex: 片段索引

返回值:

  • *pb.FileSegmentStorageSql: 文件片段存储记录
  • bool: 是否找到记录
  • error: 如果查询成功返回nil,否则返回错误信息

func (*FileSegmentStorageSqlStore) GetFileSegmentStoragesByFileID

func (s *FileSegmentStorageSqlStore) GetFileSegmentStoragesByFileID(fileID string, pubkeyHash []byte) ([]*pb.FileSegmentStorageSql, error)

GetFileSegmentStoragesByFileID 根据文件ID和公钥哈希获取文件片段存储记录 参数:

  • fileID: 文件唯一标识
  • pubkeyHash: 公钥哈希

返回值:

  • []*pb.FileSegmentStorageSql: 文件片段存储记录列表
  • error: 如果查询成功返回nil,否则返回错误信息

func (*FileSegmentStorageSqlStore) GetSharedFileSegmentStorageByFileID

func (s *FileSegmentStorageSqlStore) GetSharedFileSegmentStorageByFileID(fileID string) (*pb.ResponseSearchFileSegmentPubSub, bool, error)

GetSharedFileSegmentStorageByFileID 根据文件ID获取共享的文件片段存储记录 参数:

  • fileID: 文件唯一标识

返回值:

  • *pb.ResponseSearchFileSegmentPubSub: 检索文件的响应
  • bool: 是否找到记录
  • error: 如果查询成功返回nil,否则返回错误信息

func (*FileSegmentStorageSqlStore) ListFileSegmentStorages

func (s *FileSegmentStorageSqlStore) ListFileSegmentStorages() ([]*pb.FileSegmentStorageSql, error)

ListFileSegmentStorages 列出所有文件片段存储记录 返回值:

  • []*pb.FileSegmentStorageSql: 文件片段存储记录列表
  • error: 如果查询成功返回nil,否则返回错误信息

func (*FileSegmentStorageSqlStore) UpdateFileSegmentName

func (s *FileSegmentStorageSqlStore) UpdateFileSegmentName(fileID string, pubkeyHash []byte, newName string) error

UpdateFileSegmentName 更新文件片段的名称 参数:

  • fileID: 文件唯一标识
  • pubkeyHash: 公钥哈希
  • newName: 新的文件名

返回值:

  • error: 如果更新成功返回nil,否则返回错误信息

func (*FileSegmentStorageSqlStore) UpdateFileSegmentShared

func (s *FileSegmentStorageSqlStore) UpdateFileSegmentShared(fileID string, pubkeyHash []byte, shared bool) error

UpdateFileSegmentShared 更新文件片段的共享状态 参数:

  • fileID: 文件唯一标识
  • pubkeyHash: 公钥哈希
  • shared: 新的共享状态

返回值:

  • error: 如果更新成功返回nil,否则返回错误信息

func (*FileSegmentStorageSqlStore) UpdateFileSegmentStorage

func (s *FileSegmentStorageSqlStore) UpdateFileSegmentStorage(storage *pb.FileSegmentStorageSql) error

UpdateFileSegmentStorage 更新文件片段存储记录 参数:

  • storage: 要更新的文件片段存储记录

返回值:

  • error: 如果更新成功返回nil,否则返回错误信息

type FileSegmentStorageStore

type FileSegmentStorageStore struct {
	// contains filtered or unexported fields
}

FileSegmentStorageStore 处理 FileSegmentStorage 的数据库操作

func NewFileSegmentStorageStore

func NewFileSegmentStorageStore(db *badgerhold.Store) *FileSegmentStorageStore

NewFileSegmentStorageStore 创建一个新的 FileSegmentStorageStore 实例 参数:

  • db: badgerhold.Store 数据库实例

返回值:

  • *FileSegmentStorageStore: 新创建的 FileSegmentStorageStore 实例

type InitDBTableInput

type InitDBTableInput struct {
	fx.In

	Ctx context.Context
	Opt *fscfg.Options
	DB  *DB
}

InitDBTable 定义了初始化 UploadManager 所需的输入参数

type MapEntry

type MapEntry struct {
	Key   int64        `protobuf:"varint,1,opt,name=key,proto3" json:"key,omitempty"`
	Value pb.HashTable `protobuf:"bytes,2,opt,name=value,proto3" json:"value,omitempty"`
}

MapEntry 用于序列化单个 map 条目

type NewDBInput

type NewDBInput struct {
	fx.In // 这是一个标记结构体,表示这是一个依赖注入的输入

	Ctx context.Context // 全局上下文
}

NewDBInput 是用于传递给 NewBadgerholdStore 函数的输入结构体。 它包含了 fx.In 嵌入结构体和应用的生命周期管理器 LC。

type NewDBOutput

type NewDBOutput struct {
	fx.Out // 这是一个标记结构体,表示这是一个依赖注入的输出

	DB *DB // DB 是 Badgerhold 数据库的实例,供其他组件使用
}

NewBadgerholdStoreOutput 是 NewBadgerholdStore 函数的输出结构体。 它包含了 fx.Out 嵌入结构体和 Badgerhold 数据库实例 DB。

func NewDB

func NewDB(lc fx.Lifecycle, input NewDBInput) (out NewDBOutput, err error)

NewBadgerholdStore 是用于创建和初始化 Badgerhold 数据库的构造函数。 参数:

  • lc fx.Lifecycle: 应用的生命周期管理器
  • input NewBadgerholdStoreInput: 包含全局上下文的输入结构体

返回值:

  • out NewBadgerholdStoreOutput: 包含初始化后的数据库实例的输出结构体
  • err error: 如果初始化过程中发生错误,返回错误信息

type QueryOption

type QueryOption func(q *badgerhold.Query) *badgerhold.Query

QueryOption 定义查询选项函数类型

func WithExtension

func WithExtension(extension string) QueryOption

WithExtension 按文件扩展名筛选 参数:

  • extension: string 要筛选的文件扩展名

返回值:

  • QueryOption: 查询选项函数

func WithName

func WithName(name string) QueryOption

WithName 按文件名搜索 参数:

  • name: string 要搜索的文件名

返回值:

  • QueryOption: 查询选项函数

func WithShared

func WithShared(isShared bool) QueryOption

WithShared 筛选共享文件 参数:

  • isShared: bool 是否筛选共享文件

返回值:

  • QueryOption: 查询选项函数

func WithStatus

func WithStatus(status pb.UploadStatus) QueryOption

WithStatus 按状态筛选的查询选项 参数:

  • status: pb.UploadStatus 要筛选的上传状态

返回值:

  • QueryOption: 返回一个查询选项函数

func WithTimeRange

func WithTimeRange(startTime, endTime int64) QueryOption

WithTimeRange 按上传时间范围筛选 参数:

  • startTime: int64 时间范围的开始时间戳
  • endTime: int64 时间范围的结束时间戳

返回值:

  • QueryOption: 查询选项函数

func WithType

func WithType(fileType int32) QueryOption

WithType 按文件类型筛选(文件或文件夹) 参数:

  • fileType: int32 要筛选的文件类型

返回值:

  • QueryOption: 查询选项函数

func WithUploadTimeRange

func WithUploadTimeRange(startTime, endTime int64) QueryOption

WithTimeRange 按时间范围筛选的查询选项 参数:

  • startTime: int64 开始时间戳
  • endTime: int64 结束时间戳

返回值:

  • QueryOption: 返回一个查询选项函数

type SliceTableWrapper

type SliceTableWrapper struct {
	Entries []MapEntry `protobuf:"bytes,1,rep,name=entries,proto3" json:"entries,omitempty"`
}

SliceTableWrapper 用于包装 SliceTable map 以便序列化

func (*SliceTableWrapper) ProtoMessage

func (*SliceTableWrapper) ProtoMessage()

func (*SliceTableWrapper) Reset

func (m *SliceTableWrapper) Reset()

func (*SliceTableWrapper) String

func (m *SliceTableWrapper) String() string

type UploadFileStore

type UploadFileStore struct {
	// contains filtered or unexported fields
}

UploadFileStore 处理 UploadFileRecord 的数据库操作

func NewUploadFileStore

func NewUploadFileStore(db *badgerhold.Store) *UploadFileStore

NewUploadFileStore 创建一个新的 UploadFileStore 实例 参数:

  • db: *badgerhold.Store 数据库连接实例

返回值:

  • *UploadFileStore: 新创建的 UploadFileStore 实例

func (*UploadFileStore) ClearAllUploadFiles

func (s *UploadFileStore) ClearAllUploadFiles() error

ClearAllUploadFiles 清空所���上传文件记录 返回值:

  • error: 如果清空成功返回nil,否则返回错误信息

func (*UploadFileStore) CreateUploadFile

func (s *UploadFileStore) CreateUploadFile(file *pb.UploadFileRecord) error

CreateUploadFile 创建一个新的上传文件记录 参数:

  • file: *pb.UploadFileRecord 要创建的上传文件记录

返回值:

  • error: 如果创建成功返回nil,否则返回错误信息

func (*UploadFileStore) DeleteUploadFile

func (s *UploadFileStore) DeleteUploadFile(taskID string) error

DeleteUploadFile 删除上传文件记录 参数:

  • taskID: string 要删除的任务ID

返回值:

  • error: 如果删除成功返回nil,否则返回错误信息

func (*UploadFileStore) GetUploadFile

func (s *UploadFileStore) GetUploadFile(taskID string) (*pb.UploadFileRecord, bool, error)

GetUploadFile 根据任务ID获取上传文件记录 参数:

  • taskID: string 任务的唯一标识符

返回值:

  • *pb.UploadFileRecord: 获取到的上传文件记录
  • bool: 记录是否存在
  • error: 如果发生系统错误返回错误信息,记录不存在则返回nil

func (*UploadFileStore) GetUploadFilesByFileID

func (s *UploadFileStore) GetUploadFilesByFileID(fileID string) ([]*pb.UploadFileRecord, error)

GetUploadFilesByFileID 根据文件ID获取上传文件记录 参数:

  • fileID: string 要查询的文件ID

返回值:

  • []*pb.UploadFileRecord: 符合文件ID条件的文件记录切片
  • error: 如果查询成功返回nil,否则返回错误信息

func (*UploadFileStore) GetUploadFilesByStatus

func (s *UploadFileStore) GetUploadFilesByStatus(status pb.UploadStatus) ([]*pb.UploadFileRecord, error)

GetUploadFilesByStatus 根据状态获取上传文件记录 参数:

  • status: pb.UploadStatus 要查询的上传状态

返回值:

  • []*pb.UploadFileRecord: 符合状态条件的文件记录切片
  • error: 如果查询成功返回nil,否则返回错误信息

func (*UploadFileStore) ListUploadFiles

func (s *UploadFileStore) ListUploadFiles() ([]*pb.UploadFileRecord, error)

ListUploadFiles 列出所有上传文件记录 返回值:

  • []*pb.UploadFileRecord: 所有上传文件记录的切片
  • error: 如果查询成功返回nil,否则返回错误信息

func (*UploadFileStore) QueryUploadFiles

func (s *UploadFileStore) QueryUploadFiles(start, limit int, param string, options ...QueryOption) ([]*pb.UploadFileRecord, uint64, error)

QueryUploadFiles 高级查询上传文件记录 参数:

  • start: int 分页起始位置
  • limit: int 每页记录数
  • param: string 搜索参数
  • options: ...QueryOption 查询选项

返回值:

  • []*pb.UploadFileRecord: 查询结果文件记录切片
  • uint64: 总记录数
  • error: 如果查询成功返回nil,否则返回错误信息

func (*UploadFileStore) UpdateUploadFile

func (s *UploadFileStore) UpdateUploadFile(file *pb.UploadFileRecord) error

UpdateUploadFile 更新上传文件记录 参数:

  • file: *pb.UploadFileRecord 要更新的上传文件记录

返回值:

  • error: 如果更新成功返回nil,否则返回错误信息

func (*UploadFileStore) UpdateUploadFileStatus

func (s *UploadFileStore) UpdateUploadFileStatus(taskID string, status pb.UploadStatus, completedAt int64) error

UpdateUploadFileStatus 根据任务ID更新文件状态 参数:

  • taskID: string 任务的唯一标识符
  • status: pb.UploadStatus 要更新的状态
  • completedAt: int64 完成时间戳

返回值:

  • error: 如果更新成功返回nil,否则返回错误信息

type UploadSegmentStore

type UploadSegmentStore struct {
	// contains filtered or unexported fields
}

UploadSegmentStore 处理上传片段记录的数据库操作

func NewUploadSegmentStore

func NewUploadSegmentStore(db *badgerhold.Store) *UploadSegmentStore

NewUploadSegmentStore 创建一个新的 UploadSegmentStore 实例 参数:

  • db: *badgerhold.Store 数据库连接实例

返回值:

  • *UploadSegmentStore: 新创建的 UploadSegmentStore 实例

func (*UploadSegmentStore) BatchCreateUploadSegments

func (s *UploadSegmentStore) BatchCreateUploadSegments(segments []*pb.UploadSegmentRecord) error

BatchCreateUploadSegments 批量创建上传片段记录 参数:

  • segments: []*pb.UploadSegmentRecord 要批量创建的片段记录切片

返回值:

  • error: 如果批量创建成功返回nil,否则返回错误信息

func (*UploadSegmentStore) BatchDeleteUploadSegments

func (s *UploadSegmentStore) BatchDeleteUploadSegments(segmentIDs []string) error

BatchDeleteUploadSegments 批量删除上传片段记录 参数:

  • segmentIDs: []string 要批量删除的片段ID切片

返回值:

  • error: 如果批量删除成功返回nil,否则返回错误信息

func (*UploadSegmentStore) ClearAllUploadSegments

func (s *UploadSegmentStore) ClearAllUploadSegments() error

ClearAllUploadSegments 清空所有上传片段记录 返回值:

  • error: 如果清空成功返回nil,否则返回错误信息

func (*UploadSegmentStore) CreateUploadSegment

func (s *UploadSegmentStore) CreateUploadSegment(segment *pb.UploadSegmentRecord) error

CreateUploadSegment 创建一个新的上传片段记录 参数:

  • segment: *pb.UploadSegmentRecord 要创建的上传片段记录

返回值:

  • error: 如果创建成功返回nil,否则返回错误信息

func (*UploadSegmentStore) DeleteUploadSegment

func (s *UploadSegmentStore) DeleteUploadSegment(segmentID string) error

DeleteUploadSegment 删除上传片段记录 参数:

  • segmentID: string 要删除的片段ID

返回值:

  • error: 如果删除成功返回nil,否则返回错误信息

func (*UploadSegmentStore) DeleteUploadSegmentByTaskID

func (s *UploadSegmentStore) DeleteUploadSegmentByTaskID(taskID string) error

DeleteUploadSegmentByTaskID 删除上传切片文件记录 参数:

  • taskID: string 要删除的任务ID

返回值:

  • error: 如果删除成功返回nil,否则返回错误信息

func (*UploadSegmentStore) GetUploadProgress

func (s *UploadSegmentStore) GetUploadProgress(taskID string) (totalSegments, completedSegments int, err error)

GetUploadProgress 获取上传进度信息 参数:

  • taskID: string 任务的唯一标识符

返回值:

  • totalSegments: int 总片段数
  • completedSegments: int 已完成片段数
  • error: 如果查询失败返回错误信息

func (*UploadSegmentStore) GetUploadSegment

func (s *UploadSegmentStore) GetUploadSegment(segmentID string) (*pb.UploadSegmentRecord, error)

GetUploadSegment 根据片段ID获取上传片段记录 参数:

  • segmentID: string 片段的唯一标识符

返回值:

  • *pb.UploadSegmentRecord: 获取到的上传片段记录
  • error: 如果获取成功返回nil,否则返回错误信息

func (*UploadSegmentStore) GetUploadSegmentByChecksum

func (s *UploadSegmentStore) GetUploadSegmentByChecksum(taskID string, checksum uint32) (*pb.UploadSegmentRecord, bool, error)

GetUploadSegmentByChecksum 根据校验和和任务ID获取上传片段记录 参数:

  • taskID: string 要查询的任务ID
  • checksum: uint32 要查询的CRC32校验和

返回值:

  • *pb.UploadSegmentRecord: 获取到的上传片段记录
  • bool: 记录是否存在
  • error: 如果发生系统错误返回错误信息,记录不存在则返回nil

func (*UploadSegmentStore) GetUploadSegmentBySegmentID

func (s *UploadSegmentStore) GetUploadSegmentBySegmentID(segmentID string) (*pb.UploadSegmentRecord, bool, error)

GetUploadSegmentBySegmentID 根据片段ID获取上传片段记录 参数:

  • segmentID: string 片段的唯一标识符

返回值:

  • *pb.UploadSegmentRecord: 获取到的上传片段记录
  • bool: 记录是否存在
  • error: 如果发生系统错误返回错误信息,记录不存在则返回nil

func (*UploadSegmentStore) GetUploadSegmentByTaskIDAndIndex

func (s *UploadSegmentStore) GetUploadSegmentByTaskIDAndIndex(taskID string, index int64) (*pb.UploadSegmentRecord, bool, error)

GetUploadSegmentByTaskIDAndIndex 根据任务ID和片段索引获取上传片段记录 参数:

  • taskID: string 任务的唯一标识符
  • index: int64 片段索引

返回值:

  • *pb.UploadSegmentRecord: 获取到的上传片段记录
  • bool: 记录是否存在
  • error: 如果发生系统错误返回错误信息,记录不存在则返回nil

func (*UploadSegmentStore) GetUploadSegmentsByStatus

func (s *UploadSegmentStore) GetUploadSegmentsByStatus(taskID string, status pb.SegmentUploadStatus) ([]*pb.UploadSegmentRecord, error)

GetUploadSegmentsByStatus 根据状态和任务ID获取上传片段记录 参数:

  • taskID: string 要查询的任务ID
  • status: pb.SegmentUploadStatus 要查询的上传状态

返回值:

  • []*pb.UploadSegmentRecord: 符合状态和任务ID条件的片段记录切片
  • error: 如果查询成功返回nil,否则返回错误信息

func (*UploadSegmentStore) GetUploadSegmentsByTaskID

func (s *UploadSegmentStore) GetUploadSegmentsByTaskID(taskID string) ([]*pb.UploadSegmentRecord, error)

GetUploadSegmentsByTaskID 根据任务ID获取上传片段记录 参数:

  • taskID: string 要查询的任务ID

返回值:

  • []*pb.UploadSegmentRecord: 符合任务ID条件的片段记录切片
  • error: 如果查询成功返回nil,否则返回错误信息

func (*UploadSegmentStore) ListUploadSegments

func (s *UploadSegmentStore) ListUploadSegments() ([]*pb.UploadSegmentRecord, error)

ListUploadSegments 列出所有上传片段记录 返回值:

  • []*pb.UploadSegmentRecord: 所有上传片段记录的切片
  • error: 如果查询成功返回nil,否则返回错误信息

func (*UploadSegmentStore) UpdateSegmentStatus

func (s *UploadSegmentStore) UpdateSegmentStatus(segmentID string, status pb.SegmentUploadStatus) error

UpdateSegmentStatus 更新片段状态 参数:

  • segmentID: string 片段ID
  • status: pb.SegmentUploadStatus 新的状态

返回值:

  • error: 如果更新成功返回nil,否则返回错误信息

func (*UploadSegmentStore) UpdateUploadSegment

func (s *UploadSegmentStore) UpdateUploadSegment(segment *pb.UploadSegmentRecord) error

UpdateUploadSegment 更新上传片段记录 参数:

  • segment: *pb.UploadSegmentRecord 要更新的上传片段记录

返回值:

  • error: 如果更新成功返回nil,否则返回错误信息

func (*UploadSegmentStore) ValidateSegment

func (s *UploadSegmentStore) ValidateSegment(segment *pb.UploadSegmentRecord) error

ValidateSegment 验证片段记录的完整性 参数:

  • segment: *pb.UploadSegmentRecord 要验证的片段记录

返回值:

  • error: 如果验证通过返回nil,否则返回错误��息

Jump to

Keyboard shortcuts

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