data

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: MIT Imports: 12 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")
)

Functions

func DeleteFile

func DeleteFile(dbId string, file File, cascade bool) error

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

func DeleteTokensOfFile

func DeleteTokensOfFile(dbId string, path string) error

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

func UpsertFiles(dbId string, files []File) error

UpsertFiles uploads or updates file records in a database.

func UpsertTokens

func UpsertTokens(dbId string, 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
	DeletedAt gorm.DeletedAt `gorm:"index"`
}

File represents a file in the user's file system.

func GetFiles

func GetFiles(dbId string) ([]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
	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.

Jump to

Keyboard shortcuts

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