Documentation
¶
Overview ¶
Package data provides functions to interact with the underlying database.
Index ¶
- Variables
- func DeleteFile(dbId string, file File, cascade bool) error
- func DeleteTokensOfFile(dbId string, path string) error
- func IterUniqueTokens(dbId string) iter.Seq[TokenResult]
- func UpsertFiles(dbId string, files []File) error
- func UpsertTokens(dbId string, tokens []Token) error
- type File
- type Token
- type TokenResult
Constants ¶
This section is empty.
Variables ¶
var ( // ErrConn indicates a failure to connect to the database. ErrConn = errors.New("failed to connect to database") // ErrQuery indicates a failure during a database operation. ErrQuery = errors.New("database operation failed") )
Functions ¶
func DeleteFile ¶
DeleteFile removes a file record from the database, optionally cascading the deletion to associated tokens.
func DeleteTokensOfFile ¶
DeleteTokensOfFile removes all tokens associated with a specific file from the database.
func IterUniqueTokens ¶
func IterUniqueTokens(dbId string) iter.Seq[TokenResult]
IterUniqueTokens returns an iterator over distinct tokens in the database.
func UpsertFiles ¶
UpsertFiles uploads or updates file records in a database.
func UpsertTokens ¶
UpsertTokens inserts or updates the given tokens in a database.
Types ¶
type File ¶
type File struct {
// Path is the path to the file.
Path string `gorm:"primaryKey"`
// Size is the size of the file in bytes.
Size int
// Mtime is the modification time of the file.
Mtime time.Time
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt gorm.DeletedAt `gorm:"index"`
}
File represents a file in the user's file system.
func (*File) VersionEquals ¶
VersionEquals checks if two File instances refer to the same version of a file. Comparison is based on file path, mtime and size.
type Token ¶
type Token struct {
// Path is the path to the file from which the token was extracted.
Path string `gorm:"primaryKey"`
// Value is the token value.
Value string `gorm:"primaryKey"`
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt gorm.DeletedAt `gorm:"index"`
}
Token represents a token record in the database.
type TokenResult ¶
type TokenResult struct {
// Token is the token retrieved from the database.
Token Token
// Err is any error encountered during retrieval.
Err error
}
TokenResult represents the result of a token iteration, containing either a token or an error.