lastquery

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package lastquery provides persistence and retrieval of the most recent query results. This enables numbered references to query results for selective operations.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoLastQuery      = errors.New("no last query available")
	ErrInvalidNumber    = errors.New("invalid result number")
	ErrNumberOutOfRange = errors.New("result number out of range")
)

Errors

Functions

func ParseNumberArgs

func ParseNumberArgs(args []string) ([]int, error)

ParseNumberArgs parses multiple string arguments as numbers. Joins args with commas and delegates to ParseNumbers. This allows: "1" "3" "5" to be parsed as [1, 3, 5]

func ParseNumbers

func ParseNumbers(input string) ([]int, error)

ParseNumbers parses a string of result numbers into a slice of ints. Supports multiple formats:

  • Single number: "1"
  • Comma-separated: "1,3,5"
  • Range: "1-5"
  • Mixed: "1,3-5,7"
  • Space-separated (multiple args): handled by caller joining with commas

Returns 1-indexed numbers as provided by user.

func Path

func Path(vaultPath string) string

Path returns the path to the last-query.json file.

func Write

func Write(vaultPath string, lq *LastQuery) error

Write saves the last query results to disk.

Types

type LastQuery

type LastQuery struct {
	Query     string        `json:"query"`
	Timestamp time.Time     `json:"timestamp"`
	Type      string        `json:"type"` // "trait" or "object"
	Results   []ResultEntry `json:"results"`
}

LastQuery stores the results of the most recent query. Persisted to .raven/last-query.json for use in follow-up commands.

func Read

func Read(vaultPath string) (*LastQuery, error)

Read loads the last query results from disk. Returns ErrNoLastQuery if no last query file exists.

func (*LastQuery) GetAllIDs

func (lq *LastQuery) GetAllIDs() []string

GetAllIDs returns the IDs of all results.

func (*LastQuery) GetByNumbers

func (lq *LastQuery) GetByNumbers(nums []int) ([]ResultEntry, error)

GetByNumbers returns the entries matching the given numbers. Numbers are 1-indexed (as displayed to users). Returns an error if any number is out of range.

type ResultEntry

type ResultEntry struct {
	Num      int    `json:"num"`       // 1-indexed number for user reference
	ID       string `json:"id"`        // Unique identifier (trait ID or object ID)
	Kind     string `json:"kind"`      // "trait", "object", "reference", or "search"
	Content  string `json:"content"`   // Human-readable description
	Location string `json:"location"`  // Short location (e.g., "daily/2026-01-25:42")
	FilePath string `json:"file_path"` // Full file path
	Line     int    `json:"line"`      // Line number

	// Trait-specific fields (nil/empty for non-traits)
	TraitType  string  `json:"trait_type,omitempty"`
	TraitValue *string `json:"trait_value,omitempty"`

	// Object-specific fields (nil/empty for non-objects)
	ObjectType string                 `json:"object_type,omitempty"`
	Fields     map[string]interface{} `json:"fields,omitempty"`
}

ResultEntry represents a single result from the query. Contains all data needed for display and operations.

Jump to

Keyboard shortcuts

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