data

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package data provides functions to interact with the underlying database.

Index

Constants

This section is empty.

Variables

View Source
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

func DeleteFile(file File, cascade bool) error

DeleteFile removes a file record from the database, optionally cascading the deletion to associated tokens.

func DeleteTokensOfFile

func DeleteTokensOfFile(path string) error

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

func Setup(dirPath string, useCache bool) error

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

func UpsertFiles(files []File) error

UpsertFiles uploads or updates file records in a database.

func UpsertTokens

func UpsertTokens(tokens []Token) error

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 GetFiles

func GetFiles() ([]File, error)

GetFiles retrieves all file records from the database.

func (*File) VersionEquals

func (f *File) VersionEquals(other File) bool

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.

Jump to

Keyboard shortcuts

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