query

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 18 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package query evaluates the subset of Obsidian Bases that notesd supports (docs/specs/bases.md, ADR-0037): it reads a base's YAML, checks it against the subset, folds constants, and compiles a view's filters, sort and groups to SQL over the index's files and notes tables. store.DB runs the SQL; the engine serves it as note.query.

Every property key and literal of a base reaches SQL as a bound parameter, never as SQL text; Compile writes only fixed text. The package keeps no state between calls.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	Location string // such as views[0].filters.and[1]; empty for the document
	Expr     string // the statement, when the error is in one
	Msg      string
}

Error is a base that notesd refuses: YAML that does not parse, a key or a statement outside the subset, or a filter that cannot be compiled exactly. The engine reports it as invalidParams.

func (*Error) Error

func (e *Error) Error() string

type Options

type Options struct {
	View        *string           // the view's name; nil is the first view
	Types       map[string]string // property types by key lower-cased (vault.LoadTypes)
	This        *This             // nil when there is none
	ResolveLink func(from, target string) (string, error)
	Now         time.Time
	Loc         *time.Location // the zone of dates without one; nil is time.Local
	Limit       int            // the caller's limit, 1 to 1000
}

Options are what a compile needs besides the base.

type Plan

type Plan struct {
	Query   store.ViewQuery
	View    api.QueryView
	Views   []api.QueryView
	Notice  string // set when the view is outside the subset: nothing is queried
	Columns []api.QueryColumn
	Unshown []string
	Image   string // a cards view's image key as written; empty without one
	// contains filtered or unexported fields
}

Plan is a compiled view: the query to run, and what the result is made of.

func Compile

func Compile(source []byte, o Options) (*Plan, error)

Compile reads a base, checks the view it names against the subset and compiles it. It returns an *Error for a base that is not valid YAML or is outside the subset.

func (*Plan) Result

func (p *Plan) Result(rows []store.QueryRow, total int) *api.QueryResult

Result makes the QueryResult of the rows the plan's query returned. For a notice, nothing was queried: rows is nil and total 0.

type This

type This struct {
	ID    int64
	Path  string
	Size  int64
	MTime time.Time
	Tags  []string // as the index spells them, without '#'
	Links []string // each distinct link target as written, in order
}

This is the file a base is embedded in, or the base file itself: what `this` folds to (docs/specs/bases.md#this).

Jump to

Keyboard shortcuts

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