query

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: Apache-2.0 Imports: 14 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 contains the transport-neutral element query model and evaluator. Frontends adapt their model/index and wire formats to these types; query semantics do not depend on a transport.

Index

Constants

View Source
const (
	// PropertyID is the element identity property.
	PropertyID = "@id"
	// PropertyType is the metamodel type property.
	PropertyType = "@type"
	// PropertyName is the effective local name property.
	PropertyName = "name"
	// PropertyDeclaredName is the explicitly declared name property.
	PropertyDeclaredName = "declaredName"
	// PropertyQualifiedName is the fully qualified name property.
	PropertyQualifiedName = "qualifiedName"
	// PropertyOwner is the owning element's qualified name property.
	PropertyOwner = "owner"
	// PropertyElementType is the resolved declared element type property.
	PropertyElementType = "type"
	// PropertyIsAbstract is the abstractness property.
	PropertyIsAbstract = "isAbstract"
	// PropertyMultiplicityLower is the lower multiplicity bound property.
	PropertyMultiplicityLower = "multiplicityLower"
	// PropertyMultiplicityUpper is the upper multiplicity bound property.
	PropertyMultiplicityUpper = "multiplicityUpper"
)

Variables

View Source
var DefaultPrefixes = map[string]string{
	"sysml": rdf.SysML,
	"rdf":   rdf.RDFNS,
	"xsd":   rdf.XSD,
}

DefaultPrefixes are the prefixes available without an oslc.prefix binding.

Functions

func IsMetamodelTypeName added in v0.5.0

func IsMetamodelTypeName(name string) bool

IsMetamodelTypeName reports whether some element can report name as its @type.

func IsOrdered

func IsOrdered(name string) bool

IsOrdered reports whether a property supports numeric ordered comparisons.

func IsProperty

func IsProperty(name string) bool

IsProperty reports whether name belongs to the closed queryable-property set.

func MetamodelTypeName

func MetamodelTypeName(kind symbols.SymbolKind) string

MetamodelTypeName returns the metamodel type associated with a symbol kind.

func MetamodelTypeNameOf

func MetamodelTypeNameOf(sym *symbols.Symbol) string

MetamodelTypeNameOf returns the metamodel type name an element reports as @type, refining symbol kinds that span several metaclasses.

func ParameterNames added in v0.4.2

func ParameterNames() []string

ParameterNames returns the query parameters this implementation reads, in stable order. It is what an unknown-parameter error lists.

func PrefixedPropertyNames added in v0.5.0

func PrefixedPropertyNames(prefixes map[string]string) (names []string, unbound map[string][]string)

PrefixedPropertyNames returns the property names OSLC query text spells under prefixes, in stable order, along with the local names of every namespace those bindings leave unnamed, keyed by namespace. An oslc.prefix binding decides what the parser accepts, so a diagnostic reads the same map.

func PropertyNames

func PropertyNames() []string

PropertyNames returns the supported property names in stable order.

Types

type Element

type Element struct {
	ID         string
	Type       string
	Properties map[string]string
}

Element is a transport-neutral query result.

func Evaluate

func Evaluate(model Model, q Query) ([]Element, error)

Evaluate evaluates a query against a model, retaining declaration order unless explicit order terms are present.

type Error

type Error struct {
	Kind    ErrorKind
	Message string
}

Error is a typed query failure. A query failure must not be represented as an empty result because that would be indistinguishable from a valid no-match.

func (*Error) Error

func (e *Error) Error() string

type ErrorKind

type ErrorKind int

ErrorKind identifies a query failure.

const (
	// ErrUnknownProperty identifies an unknown query property.
	ErrUnknownProperty ErrorKind = iota + 1
	// ErrMalformed identifies malformed query syntax or structure.
	ErrMalformed
	// ErrUnorderedProperty identifies ordered comparison on an unordered property.
	ErrUnorderedProperty
	// ErrUnparsableValue identifies a value an operator cannot parse.
	ErrUnparsableValue
	// ErrUnknownScope identifies a scope absent from the model.
	ErrUnknownScope
	// ErrNoModel identifies a query without a loaded model.
	ErrNoModel
	// ErrUnsupportedScopedTerm identifies an unsupported nested property query.
	ErrUnsupportedScopedTerm
	// ErrUnsupportedWildcard identifies an unsupported property wildcard.
	ErrUnsupportedWildcard
	// ErrUnsupportedSearchTerms identifies unsupported free-text search.
	ErrUnsupportedSearchTerms
	// ErrUnsupportedLiteral identifies an unsupported literal form.
	ErrUnsupportedLiteral
)

type Model

type Model interface {
	Candidates(scope []string) ([]*symbols.Symbol, error)
	Value(sym *symbols.Symbol, property string) ([]string, bool)
	Identity(sym *symbols.Symbol) string
	Type(sym *symbols.Symbol) string
}

Model supplies the facts an evaluator needs from a parsed model.

type Operator

type Operator string

Operator is a predicate comparison operator.

const (
	Equal        Operator = "="
	NotEqual     Operator = "!="
	Less         Operator = "<"
	Greater      Operator = ">"
	LessEqual    Operator = "<="
	GreaterEqual Operator = ">="
	In           Operator = "in"
)

type OrderTerm

type OrderTerm struct {
	Property string
	Desc     bool
}

OrderTerm is one unnested sort key. Desc is true for a '-' prefix.

type Predicate

type Predicate struct {
	Property string
	Operator Operator
	Values   []string
}

Predicate is one unnested property comparison.

type PropertyReader

type PropertyReader struct {
	// contains filtered or unexported fields
}

PropertyReader reads queryable properties from shared model semantics.

func NewPropertyReader

func NewPropertyReader(index *symbols.Index, resolver *resolve.Resolver, model *semantics.Model) *PropertyReader

NewPropertyReader constructs a reader over one index and semantic model.

func (*PropertyReader) Values

func (r *PropertyReader) Values(sym *symbols.Symbol, property string) ([]string, bool)

Values returns the values of one queryable property.

type Query

type Query struct {
	Scope   []string
	Select  []string
	Where   []Predicate
	OrderBy []OrderTerm
	// Spelling names, per query property, the name the request asked for it by,
	// where that differs from the query property name.
	Spelling map[string]string
}

Query is the common representation used by structured and OSLC queries.

func ParseOSLC

func ParseOSLC(text string) (Query, error)

ParseOSLC parses a where expression. It also accepts a query-parameter string, allowing callers to pass an HTTP-style OSLC query directly.

func ParseParameters

func ParseParameters(text string) (Query, error)

ParseParameters parses oslc.where, oslc.select, oslc.orderBy, and oslc.prefix parameters. Parameter text follows URL query decoding rules.

func (Query) SpellingOf added in v0.5.0

func (q Query) SpellingOf(property string) string

SpellingOf returns the name the request asked for property by, so a frontend reports a result in terms its caller can ask the next query in.

Jump to

Keyboard shortcuts

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