qry

package
v0.0.0-...-b226945 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2024 License: BSD-2-Clause Imports: 18 Imported by: 5

README

qry

Package qry provides a way to describe and evaluate queries for local and external data.

We use a regular xelf program and mark it as query aware by providing a program specific Doc environment. The doc envirinment provides a Backend, resolves special query subjects to a query Spec with model details and stores references to all query jobs.

The query Spec, when resolved, creates a Job environment, registers it with the doc environment and then proceeds to resolves its arguments to build a Task with all relevant query details. When evaluated the spec calls the backend and returns the result.

The doc and job environments together provide access to all query tasks and results.

We also automatically provide a dom backend to query the project, schemas and models of the project.

Documentation

Overview

Package qry provides a way to describe and evaluate queries for local and external data.

Index

Constants

This section is empty.

Variables

View Source
var Backends = &Registry{}
View Source
var ErrNoProvider = fmt.Errorf("no backend provider found")
View Source
var Mod *mod.Src

Mod is the xelf module source for this package that encapsulates the qry setup.

View Source
var Prov = Backends.Register(dsetProvider{}, "file")

Functions

func AutoQuery

func AutoQuery(p *exp.Prog, pp interface{}, arg lit.Val) (lit.Mut, error)

AutoQuery generates query from and saves the query result into a tagged go struct value pointer.

func ReflectQuery

func ReflectQuery(pp interface{}) (exp.Exp, error)

ReflectQuery takes a tagged struct and generates and returns a query expression or an error. For now we just generate a query string which we then parse.

Types

type Backend

type Backend interface {
	Proj() *dom.Project
	Exec(*exp.Prog, *Job) (*exp.Lit, error)
}

Backend executes query jobs for the advertised dom schemas.

type Doc

type Doc struct {
	Par exp.Env
	Backend
	Doms *dom.Schema

	All  []*Job
	Root []*Job
}

Doc is a query program environment that resolves query subjects and collects and tracks all jobs.

func FindDoc

func FindDoc(env exp.Env) *Doc

func NewDoc

func NewDoc(env exp.Env, bend Backend) *Doc

New returns a new program environment to enable qry specs on the given backend.

func (*Doc) Add

func (p *Doc) Add(j *Job)

Add adds a job to the query document.

func (*Doc) Lookup

func (e *Doc) Lookup(s *exp.Sym, p cor.Path, eval bool) (lit.Val, error)

func (*Doc) Parent

func (e *Doc) Parent() exp.Env

func (*Doc) Subject

func (q *Doc) Subject(ref string) (*Subj, error)

Subj returns a subject from the first backend that provides ref or an error.

type DomBackend

type DomBackend struct {
	*dom.Project
}

func (*DomBackend) Exec

func (b *DomBackend) Exec(p *exp.Prog, j *Job) (*exp.Lit, error)

func (*DomBackend) Proj

func (b *DomBackend) Proj() *dom.Project

type Field

type Field struct {
	Key  string
	Name string
	Type typ.Type
	Exp  exp.Exp
	Sub  *Job
}

Field represents a selected field that can either map to a subject field or an expression. Expression fields can also contain sub queries.

type Fields

type Fields []*Field

Fields is a list of fields with a convenient lookup method.

func (Fields) Field

func (fs Fields) Field(key string) *Field

Field returns the field with key or nil.

type Job

type Job struct {
	*Doc
	Env exp.Env
	*Task
	Val *exp.Lit
	Cur lit.Val
}

Job is the environment for a query spec and holds the task and its eventual result.

func FindJob

func FindJob(env exp.Env) *Job

FindJob returns a job environment that is env or one of its ancestors.

func (*Job) Lookup

func (e *Job) Lookup(s *exp.Sym, p cor.Path, eval bool) (lit.Val, error)

func (*Job) Parent

func (e *Job) Parent() exp.Env

func (*Job) ParentJob

func (e *Job) ParentJob() *Job

ParentJob returns the parent job environment of this job or nil.

type Kind

type Kind byte

Kind indicates the query kind.

const (
	KindOne   Kind = '?'
	KindMany  Kind = '*'
	KindCount Kind = '#'
)

type LitBackend

type LitBackend struct{}

LitBackend is a query backend that operates on literal values from the program environment.

func (LitBackend) Exec

func (LitBackend) Exec(p *exp.Prog, j *Job) (*exp.Lit, error)

func (LitBackend) Proj

func (LitBackend) Proj() *dom.Project

type MemBackend

type MemBackend struct {
	*dom.Project
	*mig.Version
	Data map[string]*lit.List
}

MemBackend is a query backend that evaluates queries using in-memory literal values.

func NewDsetBackend

func NewDsetBackend(pro *dom.Project, dset mig.Dataset) (*MemBackend, error)

func NewMemBackend

func NewMemBackend(pr *dom.Project, v *mig.Version) *MemBackend

NewMemBackend returns a new memory backend for the given project.

func (*MemBackend) Add

func (b *MemBackend) Add(m *dom.Model, list *lit.Vals) error

Add converts and adds a nested list of values to this backend.

func (*MemBackend) Close

func (b *MemBackend) Close() error

func (*MemBackend) Exec

func (b *MemBackend) Exec(p *exp.Prog, j *Job) (*exp.Lit, error)

func (*MemBackend) Keys

func (b *MemBackend) Keys() (res []string)

func (*MemBackend) Proj

func (b *MemBackend) Proj() *dom.Project

func (*MemBackend) Stream

func (b *MemBackend) Stream(key string) (mig.Stream, error)

func (*MemBackend) Vers

func (b *MemBackend) Vers() *mig.Version

type Ord

type Ord struct {
	Key  string
	Desc bool
	Subj bool
}

Ord holds key sort order information.

type Provider

type Provider interface {
	Provide(uri string, pr *dom.Project) (Backend, error)
}

Provider produces backends based on an uri.

type Registry

type Registry struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*Registry) Provide

func (r *Registry) Provide(uri string, pr *dom.Project) (Backend, error)

func (*Registry) Register

func (r *Registry) Register(prov Provider, schemes ...string) Provider

type Sel

type Sel struct {
	Type typ.Type
	Fields
}

Sel describes the query selection of a subject type.

type Spec

type Spec struct {
	exp.SpecBase
	Doc  *Doc
	Task Task
}

Spec is the implementation to resolve calls on query subjects. It sets up the job environment, resolves arguments to form the task and calls the backend to execute the job when evaluated.

func (*Spec) Eval

func (s *Spec) Eval(p *exp.Prog, c *exp.Call) (lit.Val, error)

func (*Spec) Resl

func (s *Spec) Resl(p *exp.Prog, par exp.Env, c *exp.Call, h typ.Type) (exp.Exp, error)

type Subj

type Subj struct {
	Ref string
	Sel
	Model *dom.Model
	Bend  Backend
}

Subj represents a query subject of a specific backend.

type Task

type Task struct {
	Kind Kind
	*Subj
	Sel *Sel
	Res typ.Type
	Whr []exp.Exp
	Lim int64
	Off int64
	Ord []Ord
}

Task describes a all the details for one query subj call.

func (*Task) Field

func (t *Task) Field(k string) (*Field, error)

Jump to

Keyboard shortcuts

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