qry

package
v0.0.0-...-86a089b Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2019 License: BSD-2-Clause Imports: 8 Imported by: 0

Documentation

Overview

Package qry provide a way to work with external data, but can be used for local data as well. Backends provide model definitions and a way to evaluate queries to external data. The query environment detects query subjects and provides the planner for a program that manages query evaluation. Programs with queries take at least two evaluation passes. Each pass the resolved queries are planned as jobs for execution and all jobs from previous iterations are executed.

TODO: think about whether or how to support queries in loops

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

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

type Backends

type Backends []Backend

func (Backends) Find

func (bs Backends) Find(key string) (Backend, *dom.Model)

type Field

type Field struct {
	Key  string
	Name string
	Type typ.Type
	El   exp.El
	Nest []*Query
}

func (*Field) AddNested

func (f *Field) AddNested(q *Query)

type Fields

type Fields []*Field

func (Fields) Field

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

type Job

type Job struct {
	*Plan
	*Query
	Env exp.Env
	Res lit.Lit
}

Job describes a concrete query execution with all arguments evaluated.

func (*Job) Eval

func (j *Job) Eval(p *exp.Prog, env exp.Env, c *exp.Call, h typ.Type) (exp.El, error)

func (*Job) Resl

func (j *Job) Resl(p *exp.Prog, env exp.Env, c *exp.Call, h typ.Type) (exp.El, error)

type Kind

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

type LitBackend

type LitBackend struct {
	*dom.Project
	Data map[string]*lit.List
}

func (*LitBackend) Add

func (b *LitBackend) Add(m *dom.Model, list *lit.List) error

func (*LitBackend) Exec

func (b *LitBackend) Exec(p *exp.Prog, pl *Plan) error

func (*LitBackend) Proj

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

type Ord

type Ord struct {
	Key  string
	Desc bool
	Subj bool
}

type Plan

type Plan struct {
	Jobs []*Job
}

type Planner

type Planner interface {
	// Prep returns a query with an unresolved subject for key or nil
	Prep(key string) *Query
	// Plan evaluates the query arguments or an error.
	// If all arguments are evaluated it returns a new job call or a zero literal if the query
	// can be ommited (e.g. when whr evaluates to false).
	Plan(p *exp.Prog, env exp.Env, c *exp.Call, q *Query) (exp.El, error)
	// Exec executes a job using the backend and returns the result.
	Exec(p *exp.Prog, j *Job) (lit.Lit, error)
}

Planner is a program specific helper that manages available query backends.

type QryEnv

type QryEnv struct {
	Par exp.Env
	Planner
}

func NewEnv

func NewEnv(env exp.Env, bends ...Backend) *QryEnv

func (*QryEnv) Get

func (qe *QryEnv) Get(sym string) *exp.Def

func (*QryEnv) Parent

func (qe *QryEnv) Parent() exp.Env

func (*QryEnv) Qry

func (qe *QryEnv) Qry(q string, arg lit.Lit) (lit.Lit, error)

func (*QryEnv) Supports

func (qe *QryEnv) Supports(x byte) bool

type Query

type Query struct {
	Kind Kind
	Ref  string
	Subj typ.Type

	Sel *Sel
	Res typ.Type
	Whr []exp.El
	Lim int64
	Off int64
	Ord []Ord

	Planner Planner
	Model   *dom.Model
	Bend    Backend
	Err     error
}

Query describes a query definition.

func (*Query) Eval

func (q *Query) Eval(p *exp.Prog, env exp.Env, c *exp.Call, h typ.Type) (exp.El, error)

func (*Query) Resl

func (q *Query) Resl(p *exp.Prog, env exp.Env, c *exp.Call, h typ.Type) (exp.El, error)

type ReslEnv

type ReslEnv struct {
	Par exp.Env
	*Query
	*Field
	Fields
}

func (*ReslEnv) Get

func (re *ReslEnv) Get(sym string) *exp.Def

func (*ReslEnv) Parent

func (re *ReslEnv) Parent() exp.Env

func (*ReslEnv) Supports

func (re *ReslEnv) Supports(x byte) bool

type Sel

type Sel struct {
	Type typ.Type
	Fields
}

Jump to

Keyboard shortcuts

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