Documentation
¶
Overview ¶
Package data provides functions to interact with the underlying database.
Index ¶
- Variables
- func DeleteFile(file File, cascade bool) error
- func DeleteTokensOfFile(path string) error
- func IterUniqueTokens() iter.Seq[TokenResult]
- func Setup(dirPath string, useCache bool) error
- func Teardown() error
- func UpsertFiles(files []File) error
- func UpsertTokens(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") // ErrCleanup indicates a failure to clean up database resources. ErrCleanup = errors.New("failed to clean up database resources") )
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() iter.Seq[TokenResult]
IterUniqueTokens returns an iterator over distinct tokens in the database.
func Setup ¶ added in v0.3.0
Setup initializes the database connection for the specified directory. If a cached database already exists for the directory, it will be used. Alternatively, if useCache is true, the cached database will be used or created.
func Teardown ¶ added in v0.3.0
func Teardown() error
Teardown closes the database connection and cleans up temporary files.
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
}
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
}
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.